我正在嘗試使用一個總是顯示跨度的div,並且當它懸停在div上時,它下面顯示一個段落。我有什麼作品,除了我想要一些div的過渡寬度,所以他們過渡,然後離開。默認(我猜測瀏覽器默認)似乎總是下來,然後是正確的。向左移動CSS過渡寬度
鏈接到下面的小提琴和代碼。有兩個帶有標題文本的紅框div,當你將鼠標懸停在它們上面時,寬度將展開,並顯示其下面的段落。我正在做的是讓右下div(標題Here2文本)過渡到左側。所以紅色背景根本不會過渡到正確的位置。
注意:div在頁面上的位置不能改變。
http://jsfiddle.net/szfiddle/qP5fW/1/
HTML
<div class="hpBox">
<span>Title Here</span>
<p>Text here. Text here. Text here. Text here. Text here. Text here. Text here. Text here. Text here. Text here. Text here.</p>
</div>
<div class="hpBox hpBox2">
<span>Title Here2</span>
<p>Text here. Text here. Text here. Text here. Text here. Text here. Text here. Text here. Text here. Text here. Text here.</p>
</div>
CSS
.hpBox {
display: inline-block;
padding: 10px;
background: red;
-webkit-transition: 1s linear;
transition: 1s linear;
max-width:200px;
max-height:22px;
position:absolute;
}
.hpBox p {
max-height: 0;
max-width: 0;
overflow: hidden;
-webkit-transition: 2s linear;
transition: 2s linear;
}
.hpBox:hover {
max-width:400px;
max-height:200px;
}
.hpBox:hover p {
max-height: 200px;
max-width: 400px;
}
.hpBox2 {
left:60%;
top:250px;
}
完美。不需要文本對齊正確,但工作。 – user1795832