使class为row的盒子居中对齐该如何改进以上代码
时间: 2024-03-22 22:40:24 浏览: 38
盒子上下左右居中设置
要让class为row的盒子居中对齐,可以将float:left改为display:inline-block,并在父级元素上设置text-align:center。修改后的代码如下:
```css
.row {
padding: 50px 0 0 50px;
display: inline-block;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
-o-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
margin-left: -50px;
}
.row+.row {
padding-top: 50px;
}
.row:after {
content: '';
display: block;
clear: both;
height: 0;
}
.row:first-child {
padding-top: 0;
}
.row {
padding-top: 0;
}
.row.flush {
margin-left: 0;
}
.row.flush>* {
padding: 0 !important;
}
.row.half {
padding: 25px 0 0 25px;
}
.row.half+.row.half {
padding-top: 25px;
}
.row.half {
margin-left: -25px;
}
.row.double {
padding: 100px 0 0 100px;
}
.row.double+.row.double>* {
padding-top: 100px;
}
.row.double {
margin-left: -100px;
}
.parent-element {
text-align: center;
}
```
需要注意的是,父级元素的class为parent-element,这个class可以自己定义,根据实际情况修改。
阅读全文