首页 > 程序开发 > web前端 > HTML/CSS >

css之三栏布局

2017-05-26

css之三栏布局。

1.通过float left 和相对width实现
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>css三栏布局之float left与 相对width</title>
<style>
.block1,.block2,.block3{
float:left;
width:32%;
height:50px;
border:1px dashed #F00;
margin:2px;
}
.block1{background-color:red;}
.block2{background-color:blue;}
.block3{background-color:#ffe6b8;}
</style>
</head>
<body>
<div class="block1">block1</div>
<div class="block2">block2</div>
<div class="block3">block3</div>
</body>
</html>
这里写图片描述

2.绝对定位,通过absolute 定位使其脱离文档流,可以自适应定义三栏宽度

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>三栏布局css之绝对定位</title>
        <style>
            .left,.right{width: 200px;height: 200px; position: absolute;}
            .left{left:10px;background-color: red;}
            .right{right:10px;background-color: blue;}
            .center{margin:2px 210px ;background-color: yellow;height: 200px; }
        </style>
    </head>
    <body>
        <div class= "left">left</div>
        <div class = "right">right</div>
        <div class = "center">center</div>
    </body>
</html>

这里写图片描述

3.使用自身浮动,float left 和float right

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>三栏布局css之使用自身浮动</title>
        <style>
            .left,.right{width: 200px;height: 200px;}
            .left{float:left;background-color: red;}
            .right{float:right;background-color: blue;}
            .center{margin:2px 210px ;background-color: yellow;height: 200px; }
        </style>
    </head>
    <body>
        <div class= "left">left</div>
        <div class = "right">right</div>
        <div class = "center">center</div>
    </body>
</html>

这里写图片描述

相关文章
最新文章
热点推荐