【发布时间】:2017-06-28 08:41:08
【问题描述】:
【问题讨论】:
标签: css position react-native
【问题讨论】:
标签: css position react-native
您可以简单地定义一类元素,它具有指定的大小,display: inline-block 显示在一行中,负右边距重叠。
以下是用于解决您的问题的纯 HTML/CSS 示例。当然,您必须将其移植到您的 React Native 应用程序中。
.a {
display: inline-block;
height: 50px;
width: 50px;
margin-right: -20px;
background: gray;
border-radius: 50%;
border: 2px solid white;
box-shadow: 0 8px 15px #999;
}
<div class="a"></div>
<div class="a"></div>
<div class="a"></div>
<div class="a"></div>
<div class="a"></div>
【讨论】:
最简单(不是最好的方法)是这样的。 如果你使用预处理器,你可以编写这个 DRYer。
ul {
padding: 20px 0;
list-style: none;
clear: both;
}
.item {
float: left;
position: relative;
}
.item img {
border-radius: 50%;
overflow: hidden;
position: relative;
}
.item:nth-child(1) img {
background: #aaa;
border-radius: 50%;
}
.item:nth-child(2) img {
background: #bbb;
left: -20px;
}
.item:nth-child(3) img {
background: #ccc;
left: -40px;
}
.item:nth-child(4) img {
background: #ddd;
left: -60px;
}
<ul>
<li class="item"><img src="" width="50" height="50"></li>
<li class="item"><img src="" width="50" height="50"></li>
<li class="item"><img src="" width="50" height="50"></li>
<li class="item"><img src="" width="50" height="50"></li>
</ul>
【讨论】:
您可以对所有元素使用相同的样式,因为当我们有带有 flex-direction: 'row' 的行时,第一个元素将被放置在行的开头。
不要使用负边距!在IOS上可能不行。
接下来,您应该记住,在 react-native 中,每个下一个元素都将在前一个元素之上。所以你唯一应该做的就是在小块内定位图像。
【讨论】: