[英]How do I align a “box” to the middle of the screen?
I'm looking for a style which aligns the white box in this fiddle to the center of the screen. 我正在寻找一种样式,它将这种提琴中的白色框与屏幕中心对齐。
I thought I could use text-align-middle in an outer div-element. 我以为可以在外部div元素中使用text-align-middle。 But unfortunately it doesn't work.
但不幸的是,它不起作用。
I've been trying for hours now and hope you can help me. 我已经尝试了几个小时,希望您能为我提供帮助。
Thank you in advance. 先感谢您。
Add this to your current CSS : 将此添加到当前的CSS中:
.abs {
width: 100%;
}
.box {
width: 220px;
margin: auto;
}
.background1{
margin:auto;
background-color:#000000;
min-width:100%;
min-height:500px;
}
.bgcolor {
position:relative;
width:100%;
height:100%;
background-color:#000000;
opacity:0.5;
}
.abs {
display:block;
margin:auto;
width:100%;
height:500px;
}
.box {
margin:auto;
position: relative;
width:220px;
height:80px;
background-color:#ffffff;
border:1px solid grey;
}
.abs{
position: aboslute;
width: 100%;
}
.box{
/*either use*/
width: 220px; /*or larger for fixed width*/
/*or use*/
max-width: 400px; /*or any other size to give it a flexible auto size*/
margin: auto; /* or margin: 0 auto 0 auto;*/
}
Older IE versions don't allow such constructs. 较旧的IE版本不允许这种构造。 In that case you have to add:
在这种情况下,您必须添加:
.abs{
text-align: center;
}
.box{
text-align: left;
}
For backwards compatibility. 为了向后兼容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.