我正在寻找解决这个问题的方法:我有一个垂直导航,我使用的图标有不同的大小,但我通过使用不同的ID调整它们的大小来"修复"它。现在我想要对它们进行悬停效果。但是由于图标的大小不同,悬停按钮适合我的导航边框。我希望他们这样做:https://www.w3schools.com/w3css/tryw3css_templates_dark_portfolio.htm有人可以帮助我吗?
<nav class="hidden-mobile" id="menue">
<div class="navItem">
<img src="./img/home_website.png" class="icon" class="current" id="homeicon"><br>
<a class="icontitle" href="./fotowand.html">HOME</a>
<div class="after"></div>
</div>
<div class="navItem">
<img src="./img/studieninteressierte.png"class="icon"><br>
<a class="icontitle" href="">STUDIEN-<br>INTERESSIERTE</a>
<div class="after"></div>
</div>
<div class="navItem">
<img src="./img/studierende.png" class="icon" id="studierendeicon"><br>
<a class="icontitle" href="">STUDIERENDE</a>
<div class="after"></div>
</div>
<div class="navItem">
<img src="./img/unternehmen.png" class="icon" id="unternehmenicon"><br>
<a class="icontitle" href="">UNTERNEHMEN</a>
<div class="after"></div>
</div>
<div class="navItem">
<img src="./img/kontakt.png" class="icon"><br>
<a class="icontitle" href="">KONTAKT</a>
<div class="after"></div>
</div>
</nav>
这是我的 CSS
.navItem {
text-align: center;
display: inline-block;
position: relative;
margin-right: 1em;
margin-bottom: 1em;
}
.icon {
width:80px;
}
.after {
position: absolute;
top: 0;
left: 0;
width:200px;
height: 100px;
display: none;
text-align: center;
color: white;
}
.navItem:hover .after {
background-color: rgba(0, 0, 0, .6);
display: block;
left:0px;
}
导航截图
导航截图
试试这个:
-
您需要删除
after
类指定的宽度和高度。 -
您可以直接给出
navItem
的:hover
.
附上工作副本。
.navItem {
text-align: center;
display: inline-block;
position: relative;
margin-right: 1em;
margin-bottom: 1em;
}
.icon {
width:80px;
}
.after {
position: absolute;
top: 0;
left: 0;
display: none;
text-align: center;
color: white;
}
.navItem:hover {
background: rgba(0, 0, 0, .6);
}
<nav class="hidden-mobile" id="menue">
<div class="navItem">
<img src="./img/home_website.png" class="icon" class="current" id="homeicon"><br>
<a class="icontitle" href="./fotowand.html">HOME</a>
<div class="after"></div>
</div>
<div class="navItem">
<img src="./img/studieninteressierte.png"class="icon"><br>
<a class="icontitle" href="">STUDIEN-<br>INTERESSIERTE</a>
<div class="after"></div>
</div>
<div class="navItem">
<img src="./img/studierende.png" class="icon" id="studierendeicon"><br>
<a class="icontitle" href="">STUDIERENDE</a>
<div class="after"></div>
</div>
<div class="navItem">
<img src="./img/unternehmen.png" class="icon" id="unternehmenicon"><br>
<a class="icontitle" href="">UNTERNEHMEN</a>
<div class="after"></div>
</div>
<div class="navItem">
<img src="./img/kontakt.png" class="icon"><br>
<a class="icontitle" href="">KONTAKT</a>
<div class="after"></div>
</div>
</nav>
我希望这对你有帮助。祝你好运!
您可以在悬停时应用变换效果。
.navItem:hover{
transform: scale(2);
}
.navItem {
text-align: center;
display: inline-block;
position: relative;
margin-right: 1em;
margin-bottom: 1em;
transition: all 500ms ease;
}
.icon {
width:80px;
}
.after {
position: absolute;
top: 0;
left: 0;
display: none;
text-align: center;
color: white;
}
.navItem:hover {
transform: scale(2);
}
<nav class="hidden-mobile" id="menue">
<div class="navItem">
<img src="./img/home_website.png" class="icon" class="current" id="homeicon"><br>
<a class="icontitle" href="./fotowand.html">HOME</a>
<div class="after"></div>
</div>
<div class="navItem">
<img src="./img/studieninteressierte.png"class="icon"><br>
<a class="icontitle" href="">STUDIEN-<br>INTERESSIERTE</a>
<div class="after"></div>
</div>
<div class="navItem">
<img src="./img/studierende.png" class="icon" id="studierendeicon"><br>
<a class="icontitle" href="">STUDIERENDE</a>
<div class="after"></div>
</div>
<div class="navItem">
<img src="./img/unternehmen.png" class="icon" id="unternehmenicon"><br>
<a class="icontitle" href="">UNTERNEHMEN</a>
<div class="after"></div>
</div>
<div class="navItem">
<img src="./img/kontakt.png" class="icon"><br>
<a class="icontitle" href="">KONTAKT</a>
<div class="after"></div>
</div>
</nav>
<div class="navItem" id="studierendeicon">
<a class="icontitle" href="" >STUDIERENDE</a>
<div class="after"></div>
</div>
#studierendeicon{
background-image: url('./img/studierende.png')
background-position: center center; //change on needs
}
.navItem{
width: 80px;
}
让我知道它是否有效