好的,所以我试图创建一个基于图像的导航栏,当每个图像悬停时它会随着过渡而改变。
我遵循了本教程:http://css3.bradshawenterprises.com/cfimg/ 然而,转换工作现在我的所有图像都相互重叠。
完全停留在这里。
nav {
width: 1000px;
position: relative;
margin-left: auto;
margin-right: auto;
top: -16px;
}
nav li {
display: inline-block;
}
ul {
display: flex;
list-style-type: none;
}
nav img {
position: absolute;
-webkit-transition: opacity 0.3s ease-in-out;
-moz-transition: opacity 0.3s ease-in-out;
-o-transition: opacity 0.3s ease-in-out;
transition: opacity 0.3s ease-in-out;
}
nav img.top:hover {
opacity: 0;
}

<nav>
<ul>
<li>
<a href="forums">
<img class="bottom" src="inc/img/nav/communityhover.png" />
<img class="top" src="inc/img/nav/community.png" />
</a>
</li>
<li>
<a href="store">
<img class="bottom" src="inc/img/nav/store.png">
<img class="top" src="inc/img/nav/store.png">
</a>
</li>
<li>
<a href="hiscores">
<img class="bottom" src="inc/img/nav/hiscores.png">
<img class="top" src="inc/img/nav/hiscores.png">
</a>
</li>
<li>
<a href="updates">
<img class="bottom" src="inc/img/nav/updates.png">
<img class="top" src="inc/img/nav/updates.png">
</a>
</li>
<li>
<a href="support">
<img class="bottom" src="inc/img/nav/support.png">
<img class="top" src="inc/img/nav/support.png">
</a>
</li>
<li>
<a href="vote">
<img class="bottom" src="inc/img/nav/vote.png">
<img class="top" src="inc/img/nav/vote.png">
</a>
</li>
<li>
<a href="#">
<img class="bottom" src="inc/img/nav/home.png">
<img class="top" src="inc/img/nav/home.png">
</a>
</li>
</ul>
</nav>
&#13;
答案 0 :(得分:1)
您遇到的问题是li
的大小与图片的大小不同。因此,请确保width
和height
与您使用的图片相同。
nav li {
width: 350px;
height: 150px;
}
nav ul {
display: flex;
list-style-type: none;
}
nav img {
position: absolute;
-webkit-transition: opacity 0.3s ease-in-out;
-moz-transition: opacity 0.3s ease-in-out;
-o-transition: opacity 0.3s ease-in-out;
transition: opacity 0.3s ease-in-out;
}
nav img.top:hover {
opacity: 0;
}
<nav>
<ul>
<li>
<a href="#">
<img class="bottom" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=a1&w=350&h=150" />
<img class="top" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=a2&w=350&h=150" />
</a>
</li>
<li>
<a href="#">
<img class="bottom" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=b1&w=350&h=150">
<img class="top" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=b2&w=350&h=150">
</a>
</li>
<li>
<a href="#">
<img class="bottom" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=c1&w=350&h=150">
<img class="top" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=c2&w=350&h=150">
</a>
</li>
</ul>
</nav>