好的,所以我使用這個來讓自己成爲一個標題,當用戶將鼠標懸停在標籤上時,它會顯示一行。我試圖在不改變用戶懸停在其上的大小的情況下做到這一點。我想要一條線出現,但沒有別的事情會發生。邊框不改變文字的大小
這裏是一個小提琴, 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)。 –