我有一個包含圖像和用戶名的框。最初寬度是固定的以節省空間,並且我想讓分部展開以顯示完整內容。我已經實現了這一點,但我無法添加transition
以使動畫順暢。CSS:轉換不能用於懸停
爲什麼它不起作用?
.peer-person {
position: relative;
z-index: 1000;
width: 9.5%;
min-width: 66px;
margin: 0px 0px 5px 0px;
padding: 6px 0px 5px 0px;
display: inline-block;
border: 2px solid #efefef;
border-radius: 5px;
-webkit-transition: all 1s ease-in-out 0s;
-moz-transition: all 1s ease-in-out 0s;
transition: all 1s ease-in-out 0s;
}
.hover-container:hover>.peer-person {
z-index: 1001;
background-color: white;
width: auto;
}
.hover-container {
display: inline-block;
width: 9.5%;
min-width: 66px;
}
.peer p {
margin: 0px;
padding: 3px;
padding-bottom: 0px;
color: grey;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
<span class="hover-container">
<span class="peer-person">
<a href="#" role="button" class="peer" aria-expanded="false">
<img src="http://via.placeholder.com/36x36" class="img-circle">
<p>1.LONGUSERNAMELONGLONG</p>
</a>
</span>
</span>
<span class="hover-container">
<span class="peer-person">
<a href="#" role="button" class="peer" aria-expanded="false">
<img src="http://via.placeholder.com/36x36" class="img-circle">
<p>2.LONGUSERNAMELONGLONG</p>
</a>
</span>
</span>
<span class="hover-container">
<span class="peer-person">
<a href="#" role="button" class="peer" aria-expanded="false">
<img src="http://via.placeholder.com/36x36" class="img-circle">
<p>3.LONGUSERNAMELONGLONG</p>
</a>
</span>
</span>
嗨,謝謝你解釋得很好的答案。是的,它確實可以滿足我需要的一切。但是我還沒有把你的標記標記爲正確的答案。問題是連續有多個這樣的問題。我已經更新了問題中的代碼。 將懸停容器的寬度更改爲自動會導致多個框之間有空白空間。 – Rithwik
@Rithwik用一個新的編碼編輯我的答案:D –
哈哈。 :D 我只是在思考類似的問題。 但你做到了。非常感謝。 – Rithwik