css实现水平对齐,如图css
有人会说css实现这种水平对齐要兼容ie8还不简单吗?使用float: left,或者display: inline-block,不就能够了吗?是的,最经常使用的最简单方式就是上面这两种,但还有一种方式也能够实现,那就是使用display: table-cell;spa
<style type="text/css"> *{ margin: 0; padding: 0; box-sizing: border-box; } .container{ width: 1000px; height: 1000px; margin: 100px; background-color: #f60; } .left{ /*关键点在于将两个元素设置为display:table-cell*/ display: table-cell; vertical-align: top; width: 20%; min-width: 200px; height: 400px; background-color: #ccc; } .right{ display: table-cell; vertical-align: top; /*即便宽度设为2000px,元素的内容仍是能够正常显示*/ width: 2000px; height: 600px; background-color: #f10; } </style>
<div class="container"> <div class="left">left</div> <div class="right">right</div> </div>