【发布时间】:2018-06-20 14:47:31
【问题描述】:
我有 3 个带有 display: block 的列表项。我希望偶数元素的位置稍微低一点,但是当我尝试使用 margin-top 时,我的所有元素都位于较低的位置。
.hero__description-right {
margin-left: 0px;
width: 100%;
height: auto;
margin-bottom: 20px;
}
.description__item {
margin-top: 0px;
display: inline-block;
position: relative;
clear: both;
}
.description__item:last-child {
margin-bottom: 0px;
}
.description__item:nth-child(2n) {
margin-left: 0px;
margin-top: 20px;
}
<div class="hero__description-right">
<li class="description__item">
<h2><span class="hashtag">#</span> Text</h2>
</li>
<li class="description__item test">
<h2><span class="hashtag">#</span> Text</h2>
</li>
<li class="description__item">
<h2><span class="hashtag">#</span> Text</h2>
</li>
</div>
如何仅定位偶数元素?提前致谢!
【问题讨论】:
-
请澄清您的具体问题或添加其他详细信息以准确突出您的需要。正如目前所写的那样,很难准确地说出你在问什么。
-
寻求代码帮助的问题必须包含重现它所需的最短代码在问题本身中最好在Stack Snippet 中。见How to create a Minimal, Complete, and Verifiable example