在 CSS 中,left
表示元素与父元素左侧之间的距离,例如<body>
,或带有 的元素position: relative
。
其他的也一样,例如bottom
表示离底部边缘多远。
但是,我做了一个允许从中心定位的示例:http: //jsfiddle.net/tbRfm/1/。
HTML:
<div class="wrapper">
<div class="inner">
Inner stuff here, or set a <code>background-image</code>.
</div>
</div>
CSS:
.wrapper {
position: relative;
left: 200px;
top: 100px;
width: 100px;
height: 100px;
}
.inner {
position: absolute;
width: 100px;
height: 100px;
right: 50px;
bottom: 50px;
background: #eee;
text-align: center
}
这适用于所有 IE 版本(至少我可以在IE NetRenderer测试的版本:IE5.5 - IE10)。
简单测试:如果您设置left
和的top
值.wrapper
0
,则该框将被截断:http: //jsfiddle.net/tbRfm/3/。