HTML5 布局

本文介绍了两种实现两栏布局和三栏布局的方法。在两栏布局中,通过浮动元素和设置margin实现;在三栏布局中,利用calc()函数动态计算宽度,调整元素位置。这些布局技巧对于前端开发者来说是构建响应式网页的基础。
摘要由CSDN通过智能技术生成

两栏布局

方案一
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        *{
            margin: 0px;
            padding: 0px;
        }
        body,html{
            height: 100%;
        }

        .box1{
            width: 200px;
            height: 100%;
            background-color: tomato;
            float: left;
        }
        .box2{
            /*box2不能设置宽度,否则的话就没有自适应了*/
            height: 100%;
            margin-left: 200px;
            background-color: thistle;
        }
    </style>
</head>

<body>
    <div class="box1"></div>
<div class="box2"></div>
</body>
</html>
方案二
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        *{
            margin: 0px;
            padding: 0px;
        }
        body,html{
            height: 100%;
        }

        .box1{
            width: 200px;
            height: 100%;
            background-color: tomato;
            float: left;
        }
        .box2{
            /*calc 用于动态计算长度值,前后必须留空格 这个函数支持加减乘数的运算*/
            height: 100%;
            width: calc(100% - 200px);
            background-color: thistle;
            float: left;
        }
    </style>
</head>

<body>
    <div class="box1"></div>
<div class="box2"></div>
</body>
</html>

三栏布局

方案一
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        *{
            margin: 0px;
            padding: 0px;
        }
        body,html{
            height: 100%;
        }

        .box1{
            width: 200px;
            height: 100%;
            background-color: tomato;
            float: left;
        }
        .box2{
            /*calc 用于动态计算长度值,前后必须留空格*/
            height: 100%;
            width: calc(100% - 400px);
            background-color: thistle;
            float: left;
        }
        .box3{
            height: 100%;
            width: 200px;
            background-color: antiquewhite;
            float: left;
        }
    </style>
</head>

<body>
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
</body>
</html>
方案二
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        *{
            margin: 0px;
            padding: 0px;
        }
        body,html{
            height: 100%;
        }

        .box1{
            width: 200px;
            height: 100%;
            background-color: tomato;
            float: left;
        }
        .box2{
            /*calc 用于动态计算长度值,前后必须留空格*/
            height: 100%;
            width: 100%;
            background-color: thistle;
            margin-left: 200px;
            margin-right: 200px;
        }
        .box3{
            height: 100%;
            width: 200px;
            background-color: antiquewhite;
            float: right;
        }
    </style>
</head>

<body>
<div class="box1"></div>
<div class="box3"></div>
<div class="box2"></div>

</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LyaJpunov

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值