//DOM公共部分結構
<div class='box'>
<div class='box-left'></div>
<div class='box-right'></div>
</div>
複製代碼
.box{
height: 200px;
}
.box>div{
height: 100%;
}
.box-left{
width: 200px;
float: left;
background: blue;
}
.box-right{
margin-left: 200px;
background: red;
}
複製代碼
.box{
height: 200px;
}
.box>div{
height: 100%;
}
.box-left{
width: 200px;
float: left;
background: blue;
}
.box-right{
width: calc(100% - 200px);//注意這邊寫法 ‘-’ 號兩邊要要空格 否則不識別
float: right;
background: red;
}
複製代碼
.box{
height:200px;
}
.box>div{
height:100%;
}
.box-left{
width:200px;
background:blue;
float:left
}
.box-right{
overflow:hidden;
background:red;
}
複製代碼
.box{
height:200px;
display: flex;
}
.box>div{
height:100%;
}
.box-left{
width:200px;
background:blue;
float:left
}
.box-right{
background: red;
flex-grow: 1;//flex-grow屬性都爲1,則它們將等分剩餘空間
}
複製代碼
雙飛翼佈局實現代碼:html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<style>
body{
font-size: 50px;
font-weight: bolder;
margin: 0;
padding: 0;
text-align: center;
}
.header{
height: 60px;
background: rosybrown;
}
.footer{
height: 60px;
background: rosybrown;
}
.context{
overflow: hidden;
}
.context>div{
float: left;
height: 300px;
line-height: 300px;
}
.middle{
width: 100%;
}
.left{
width: 200px;
background: cornflowerblue;
margin-left: -100%;
}
.right{
width: 200px;
background: darkblue;
margin-left: -200px;
}
.center{
background: darkorange;
margin: 0 200px;
}
</style>
<body>
<div class="header">header</div>
<div class="context">
<div class="middle">
<div class="center">center</div>
</div>
<div class="left">left</div>
<div class="right">right</div>
</div>
<div class="footer">footer</div>
</body>
</html>
複製代碼
聖盃佈局實現代碼面試
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<style>
body{
font-size: 50px;
font-weight: bolder;
margin: 0;
padding: 0;
text-align: center;
}
.header{
height: 60px;
background: rosybrown;
}
.footer{
height: 60px;
background: rosybrown;
}
.context{
overflow: hidden;
padding: 0 200px;
}
.context>div{
float: left;
height: 300px;
line-height: 300px;
}
.center{
width: 100%;
background: darkorange;
box-sizing: border-box;
}
.left{
width: 200px;
margin-left: -200px;
background: cornflowerblue;
position: relative;
}
.right{
width: 200px;
margin-left: -200px;
background: darkblue;
position: relative;
left: 200px;
}
</style>
<body>
<div class="header">header</div>
<div class="context">
<div class="left">left</div>
<div class="center">center</div>
<div class="right">right</div>
</div>
<div class="footer">footer</div>
</body>
</html>
複製代碼
ps:感受我不怎麼用到這個東西,我都是flex佈局來的!bash
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<style>
.center{
width: 300px;
height: 300px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -150px;
margin-left: -150px;
background: burlywood;
text-align: center;
}
</style>
<body>
<div class="center">center</div>
</body>
</html>
複製代碼
方法二佈局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<style>
.center{
width: 300px;
height: 300px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
background: burlywood;
text-align: center;
}
</style>
<body>
<div class="center">center</div>
</body>
</html>
複製代碼
方法三flex
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<style>
.center{
width: 300px;
height: 300px;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
background: burlywood;
text-align: center;
}
</style>
<body>
<div class="center">center</div>
</body>
</html>
複製代碼
還有啥問題我想不大起來了,後面遇到了在補吧。不過如今的flex 佈局更方便的 但會遇到一些兼容性問題,好比在ie中和min-height min-width 不能兼容 這個得注意。不過有這個方法以後佈局就更簡單了。ui