0
有3個街區向右擴展。如何使第三個元素向左擴展並避免移動塊本身(元素必須保持原位)?如何將元素展開到左側?
$(".block").hover(function() {
$(this).toggleClass('expanded');
});
.block {
width: 100px;
height: 100px;
border: 1px solid #000;
overflow: hidden;
display: inline-block;
position: absolute;
}
.test {
width: 100px;
height: 100px;
border: 1px solid red;
}
.left, .right {
display: inline-block;
}
.right {
background-color: red;
}
.expanded {
width: 220px;
position: absolute;
z-index: 10;
}
/* .block:hover {
width: 220px;
} */
.block-second {
left: 120px;
}
.block-third {
left: 240px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="block">
<div class="test left">
<p>first</p>
</div>
<div class="test right">
<p>111</p>
</div>
</div>
<div class="block block-second">
<div class="test left">
<p>second</p>
</div>
<div class="test right">
<p>222</p>
</div>
</div>
<div class="block block-third">
<div class="test left">
<p>third</p>
</div>
<div class="test right">
<p>333</p>
</div>
</div>
試過的位置是:絕對的;頂部:0;右:0; 試圖將塊換成固定寬度的div。無法找到相似的例子。
http://jsfiddle.net/J99uQ/2/ – athi