html--左側固定寬度,右側自適應寬度佈局
阿新 • • 發佈:2019-02-02
左側固定寬度,右側自適應寬度結構
原理:
定位(position)中的absolute屬性值可以使元素脫離正常文件流,後面的元素向上移動,將後面的元素設定margin-left屬性值設定為前面脫離文件流的元素的寬度,就可以完全顯示後面的內容。
html程式碼如下:
<!DOCTYPE html>
<html>
<head>
<title>左側固定寬度,右側自適應頁面</title>
<meta charset="utf-8">
<style type="text/css">
.container{
height: 200px;
background-color: #FFF;
}
.menu{
margin: 0 auto;
width: 1200px;
height: 200px;
background-color: gray;
}
.left{
position: absolute;
width: 200px;
height :200px;
background-color: red;
}
.right{
height: 200px;
margin-left:200px;
background-color: blue;
}
</style>
</head>
<body>
<div class="container">
<div class="menu">
<div class ="left">left</div>
<div class="right">right</div>
</div>
</div>
</body>
</html>
效果圖: