好的,所以我使用这个来让自己成为一个标题,当用户将鼠标悬停在标签上时,它会显示一行。我试图在不改变用户悬停在其上的大小的情况下做到这一点。我想要一条线出现,但没有别的事情会发生。边框不改变文字的大小
这里是一个小提琴, Fiddle
HTML:
<div class="header">
<div class="header-tab">
<div class="center-vertical">
Main
</div>
</div>
</div>
CSS
.header-tab{
height:100%;
display:inline-block;
padding:0 1vw 0 1vw;
text-transform:uppercase;
font-weight:450;
color:white;
}
.header-tab:hover{
color:#ff704d;
background:gray;
box-sizing: border-box;
border-bottom:3px solid #ff704d;
}
.center-vertical{
position: relative;
top: 50%;
transform: translateY(-50%);
-webkit-transform: translateY(-50%);
}
.header{
height:5vw;
background:black;
}
body{
margin:0;
}
我认为,这是因为垂直居中的,但我不是很确定。 谢谢!
编辑:我不想让它喜欢,跳起来。
的WhatsUp与downvote:/? –
此问题已被多次询问。基本上,在非悬停状态下添加透明边框,并在':hover'状态下更改颜色。 –
[1](http://stackoverflow.com/questions/27648342/)[1](http://stackoverflow.com/questions/27648342/)(http://stackoverflow.com/questions/27648342/)防止高度变化时添加边框与框大小),[3](http://stackoverflow.com/questions/9612758/add-a-css-border-on-hover -without-moving-the-element),[4](http://stackoverflow.com/questions/3254587/when-1-px-border-is-added-to-div-div-size-increases-dont-想要做的)... [搜索](http://stackoverflow.com/search)和[research](http://stackoverflow.com/help/how-to-ask)。 –