我有困難使用第n個孩子選擇器。我有這樣的HTML代碼:第N個孩子選擇器
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來選擇每個圖像以將其向下移動:CSS屬性?
的jsfiddle http://jsfiddle.net/FGGpY/5/
請準備小提琴 –
不太清楚你的意思......像只刪除了'頂:0像素;'? –
在這裏測試你的代碼http://jsfiddle.net/併發布結果,以便我們可以更好地理解活工作代碼 –