我在使用第 n 个子选择器时遇到了困难。我有这个 html 代码:
HTML
<div class="container">
<ul class="mh-menu">
<li>
<a href="#">
<span>Chairman of the Board</span>
<span>Name</span>
</a>
<img src="images/richard.jpg" alt="richard"/>
<p>Some Text</p>
</li>
<li>
<a href="#">
<span>Chief Executive Officer</span>
<span>Name</span>
</a>
<img src="images/scott.jpg" alt="scott"/>
<p>Some text</p>
</li>
<li>
<a href="#">
<span>Executive Vice President</span>
<span>Name</span>
</a>
<img src="images/dana.png" alt="dana"/>
<p>Some Text</p>
</li>
<li>
<a href="#">
<span>Executive Vice President</span>
<span>Name</span>
</a>
<img src="images/jay.jpg" alt="jay"/>
<p>Some text</p>
</li>
</ul>
</div>
随着这个CSS:
CSS
.mh-menu li img {
position: absolute;
z-index: 1;
left: 0px;
top: 0px;
opacity: 0;
-webkit-transition: left 0.4s ease-in-out, opacity 0.6s ease-in-out;
-moz-transition: left 0.4s ease-in-out, opacity 0.6s ease-in-out;
-o-transition: left 0.4s ease-in-out, opacity 0.6s ease-in-out;
-ms-transition: left 0.4s ease-in-out, opacity 0.6s ease-in-out;
transition: left 0.4s ease-in-out, opacity 0.6s ease-in-out;
}
.mh-menu li p {
text-align: left;
position: absolute;
z-index: 1;
left: 540px;
top: 0px;
opacity: 0;
-webkit-transition: left 0.4s ease-in-out, opacity 0.6s ease-in-out;
-moz-transition: left 0.4s ease-in-out, opacity 0.6s ease-in-out;
-o-transition: left 0.4s ease-in-out, opacity 0.6s ease-in-out;
-ms-transition: left 0.4s ease-in-out, opacity 0.6s ease-in-out;
transition: left 0.4s ease-in-out, opacity 0.6s ease-in-out;
}
.mh-menu li:hover img {
left: 300px;
opacity: 1;
}
.mh-menu li:hover p {
left: 540px;
opacity: 1;
text-align: left;
}
基本上它是一个菜单,当您将鼠标悬停在名称上时,图像和一些文本会从右侧弹出。现在图像和文本都在顶部弹出,但是我想将图像向下移动,以便当您将鼠标悬停在名称上时,图像会从名称范围的顶部弹出。如何使用 nth-child 选择每个图像以使用 top: CSS 属性将其向下移动?
jsFiddle http://jsfiddle.net/FGGpY/5/