水平和垂直居中DIV 有沒有辦法垂直和水平地居中DIV,但重要的是,當(dāng)窗口小于內(nèi)容時,內(nèi)容不會被切割 .div必須具有背景顏色和寬度和高度。我總是將div與絕對定位和負(fù)邊距居中,就像在提供的示例中一樣。但它存在的問題是它會削減內(nèi)容。有沒有一種方法可以在沒有這個問題的情況下使div .content居中?我在這里有一個例子:http://jsbin.com/iquviq/1/editCSS: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-我的問題非常清楚,并以黑色為條件:“當(dāng)窗口小于內(nèi)容時,內(nèi)容不會被刪除”
添加回答
舉報
0/150
提交
取消