欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

详细介绍CSS之三栏布局的实例(图)

程序员文章站 2022-03-28 09:37:49
...
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>
<p class="block1">block1</p>
<p class="block2">block2</p>
<p class="block3">block3</p>
</body>
</html>

详细介绍CSS之三栏布局的实例(图)

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>
        <p class= "left">left</p>
        <p class = "right">right</p>
        <p class = "center">center</p>
    </body>
</html>

详细介绍CSS之三栏布局的实例(图)

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>
        <p class= "left">left</p>
        <p class = "right">right</p>
        <p class = "center">center</p>
    </body>
</html>

详细介绍CSS之三栏布局的实例(图)

以上就是详细介绍CSS之三栏布局的实例(图)的详细内容,更多请关注其它相关文章!

相关标签: CSS,三栏布局