先将父元素的布局方式设置为flex,并向右靠齐
结构代码
<view class="father">父元素
<view class="left"><view>
<view class="right"><view>
<view>
.father {
display: flex;
justify-content: flex-end;
}
2、设置left元素的右边距为auto,left会直接顶开从而向左边靠齐
.father .left{
margin-right: auto;
}
补充
/* 对齐方式 */
justify-content: center; /* 居中排列 */
justify-content: start; /* 从行首开始排列 */
justify-content: end; /* 从行尾开始排列 */
justify-content: flex-start; /* 从行首起始位置开始排列 */
justify-content: flex-end; /* 从行尾位置开始排列 */
justify-content: left; /* 一个挨一个在对齐容器得左边缘 */
justify-content: right; /* 元素以容器右边缘为基准,一个挨着一个对齐, */
/* 基线对齐 */
justify-content: baseline;
justify-content: first baseline;
justify-content: last baseline;
/* 分配弹性元素方式 */
justify-content: space-between; /* 均匀排列每个元素
首个元素放置于起点,末尾元素放置于终点 */
justify-content: space-around; /* 均匀排列每个元素
每个元素周围分配相同的空间 */
justify-content: space-evenly; /* 均匀排列每个元素
每个元素之间的间隔相等 */
justify-content: stretch; /* 均匀排列每个元素
'auto'-sized 的元素会被拉伸以适应容器的大小 */
/* 溢出对齐方式 */
justify-content: safe center;
justify-content: unsafe center;
/* 全局值 */
justify-content: inherit;
justify-content: initial;
justify-content: unset;
获取键盘高度-uniapp
uni.onKeyboardHeightChange(res => {
this.keyboardHeight = res.height
})
页面回滚到最底部-uniapp
this.$nextTick(() => {
uni.pageScrollTo({
scrollTop: 999999, //滚动到页面的目标位置(单位px)
duration: 0 //滚动动画的时长,默认300ms,单位 ms
});
})
div标签防止数字/英文多了会溢出
word-break: break-all;