父级组件:position: relative;
子级组件:position: absolute;
给子级组件设置left,right,top和bottom确定组件的位置
还可以设置z-index
,设置子级的重叠顺序
wxml文件:
<view class="test" bindlongtap="_handerLongTap">
<image src="{{testItems.imageSrc}}" mode="aspectFill"/>
<text>{{testItems.imageName}}</text>
<view class="deleteBtn" hidden="{{!isShowDelete}}">X</view>
</view>
wxss文件
.test{
height: 130px;
width: 100px;
border: 1px solid #f00;
text-align: center;
margin-bottom: 5px;
position: relative;
}
.test .deleteBtn{
position: absolute;
top:-6px;
right: -4px;
background-color: red;
width: 20px;
height: 20px;
border-radius: 50%;
color: white;
text-align: center;
line-height: 20px;
}
红色的删除键