起因是看到了一篇掘金上的文章(点击打开链接),感觉还有别的实现方式,就动手写了一下。(ps:当然也可以使用flex)
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>使用table-cell 实现三栏布局,左右定宽中间自适应</title>
<style>
.parent {
display: table;
width: 100%;
}
.parent> div {
display: table-cell;
height: 200px;
border: 1px solid red;
box-sizing: border-box;
}
.left {
width: 100px;
}
.right {
width: 200px;
}
</style>
</head>
<body>
<div class="parent">
<div class="left">Left</div>
<div class="main">Main</div>
<div class="right">Right</div>
</div>
</body>
</html>