的較小的div內我想達到下述效果:http://jsfiddle.net/3KJta/1/如何水平居中可變寬度的較大的div,可變寬度
然而該解決方案我有使用已知寬度爲小的div和更大的div。我需要這個與變量大小的divs一起使用。這個用例是一個工具提示,出現在一個較小的靈活大小的元素上面。工具提示內容是未知的,所以寬度可以是任何東西。
到目前爲止,我有:
<div class="small">
<div class="smaller"></div>
<div class="larger"></div>
</div>
和
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
div {
border: 2px solid black;
}
.small {
width: 50px;
height: 50px;
position: absolute;
left: 200px;
top: 50px;
text-align: center;
}
.smaller {
width: 20px;
height: 20px;
border-color: red;
display: inline-block;
}
.larger {
width: 200px;
height: 200px;
border-color: blue;
display: inline-block;
margin-left: -75px /* NOTE: in reality, .small has a variable width, and so does .larger, so i can't just take off this fixed margin */
}
哦,那是聰明:)幸運的是我只支持IE9 +所以這正是我所需要的 - 謝謝! – magritte