.out { } .in { margin: 0 auto; }
.out { text-align: center; } .in { display: inline-block; }
.out { display: flex; justify-content:center; } .in { }
.out { position: relative; } .container { position: absolute; left:50%; transform: translate(-50%,0) } .in { float: left; }
.out { text-align:center; }
.out { } .in { margin-top: 75px; }
.out { box-sizing: border-box; padding-top: 75px; } .in { }
.out { position: relative; } .in { position: absolute; top: 50%; transform: translate(0,-50%); }
/*使用flex布局*/ .out { display: flex; align-items: center; } .in { }
.out { } .in { line-height: 20px; }
水平垂直居中
知道高度
.out { } .in { margin: 50px auto; }
//同理也可以设置padding
//使用定位实现 .out { position: relative; } .in { position: absolute; top: 50%; left: 50%; margin-left: -50px; margin-top: -50px; }
不知道高度
//定位结合transfrom属性 .out { position: relative; } .in { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); }
//使用flex布局 .out { display: flex; justify-content: center; align-items: center; } .in { }
两列布局(左边固定右边自适应)
.left { float: left; width: 200px; } .right { margin-left: 200px; }
.left { float: left; width: 200px; } .right { overflow: auto; }
.container { display: flex; } .left { width: 200px; } .right { flex: 1; }
.middle { width: 100%; float: left; box-sizing: border-box;
} /*使文字不被遮挡*/
.middle .container {
margin:0 200px;
} .left { width: 200px; float: left; /*调整负边距回到应在的位置*/ margin-left: -100%; } .right { width: 200px; float: left; margin-left: -200px; }
注意**:所有div都要浮动,并且middle必须写在前面
.middle { width: 100%; float: left; padding: 0 200px 0 200px; box-sizing: border-box; } .left { width: 200px; float: left; margin-left: -100%; } .right { width: 200px; float: left; margin-left: -200px; }
.middle { flex: 1; } .left { width: 200px; } .right { width: 200px; }
注意**:需要按照left,middle,right的顺序写
.middle { width: 100%; } .left { width: 200px; float: left; } .right { width: 200px; float: right; }
注意**:书写方式left,right,middle;文字会避开浮动模块,不需要过多处理了
.middle { width: 100%; } .left { width: 200px; position: absolute; left: 0; top: 0; } .right { width: 200px; position: absolute; right: 0; top: 0; }
原文:https://www.cnblogs.com/longlongdan/p/10532891.html