有没有一种方法可以让一个
我通常使用绝对定位和负边距来居中
我在这里提供了一个示例可以尝试:http://jsbin.com/iquviq/1/edit
CSS:
body { margin: 0px; }
.background {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
background-color: yellow;
}
/*
is there a better way than the absolute positioning and negative margin to center the div .content: div with background color a width and a hight?:
*/
.content {
width: 200px;
height: 600px;
background-color: blue;
position:absolute;
top:50%;
left:50%;
margin-left:-100px;/* half width*/
margin-top:-300px;/* half height*/
}
HTML:
<div class="background">
<div class="content"> some text </div>
</div>
我的问题不是“如何水平垂直居中元素?”的重复。 1- 我的问题在那个问题之前就被提出了(请检查日期)。 2- 我的问题非常清楚地说明并列出了条件:“当窗口小于内容时,内容不会被裁剪”。