左右布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>layout</title>
<style>
.left {
float: left;
width: 30%;
height: 100%;
background-color: yellow;
}
.right {
float: right;
width: 70%;
height: 100%;
background-color: green;
}
.container {
width: 1000px;
height: 500px;
border: 1px solid red;
}
</style>
</head>
<body>
<div class="container">
<div class="left"></div>
<div class="right"></div>
</div>
</body>
</html>
leftright.png
左中右布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>layout</title>
<style>
.left {
float: left;
width: 30%;
height: 100%;
background-color: yellow;
}
.middle {
float: left;
width: 30%;
height: 100%;
background-color: red;
}
.right {
float: right;
width: 40%;
height: 100%;
background-color: green;
}
.container {
width: 1000px;
height: 500px;
border: 1px solid red;
}
</style>
</head>
<body>
<div class="container">
<div class="left">左边</div>
<div class="middle">中间</div>
<div class="right">右边</div>
</div>
</body>
</html>
lmr.png
水平居中
行内元素
只需要使用text-align:center
就可以
块级元素
首先为元素设置宽度,然后使用margin:0 auto
就行
垂直居中
元素height = line-height
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>layout</title>
<style>
.box {
background-color: #666666;
color: red;
height: 100px;
line-height: 100px;
}
</style>
</head>
<body>
<div class="box">
垂直居中
</div>
</body>
</html>
sj.png
css技巧
可以访问csstricks网站有好多css技巧
网友评论