/* 红色区域的大小是多少?200 - 20*2 - 20*2 = 120 */ .box { width: 200px; height: 200px; padding: 20px; margin: 20px; background: red; border: 20px solid black; box-sizing: border-box; }
/* 标准模型 */ box-sizing:content-box; /*IE模型*/ box-sizing:border-box;
用 padding-bottom
撑开边距css
section { width:100%; padding-bottom: 100%; background: #333; }
<div><span>我是多行文字。我是多行文字。我是多行文字。我是多行文字。我是多行文字。我是多行文字。我是多行文字。我是多行文字。我是多行文字。我是多行文字。</span></div> <div><span>我是一行文字</span></div> <style> div{text-align: center;} div span{display: inline-block;text-align: left;} </style>
贴上腾讯大佬的一篇文章:16种方式实现水平居中垂直居中html
flex作自适应布局很容易,但兼容性很差,这里统一不用flex布局前端
.left{ float:left; width:300px; margin-right: 10px; background: red; } .right{ overflow: hidden; /* 建立BFC */ background: yellow; }
table
布局兼容性最好,固然flex
布局的align-items: stretch;
也行面试
<div class="layout"> <div class="layout left">left</div> <div class="layout right">center</div> </div> <style> .layout{ display: table; width: 100%; } .layout div{ display: table-cell; } .layout .left{ width: 50%; height: 200px; background: red; } .layout .right{ width: 50%; background: yellow; } </style>
.shape { width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-top: 50px solid transparent; border-bottom: 50px solid blue; background: white; }
BFC触发条件:浏览器
BFC特性:布局
2019前端面试系列——CSS面试题
2019前端面试系列——JS面试题
2019前端面试系列——JS高频手写代码题
2019前端面试系列——Vue面试题
2019前端面试系列——HTTP、浏览器面试题post