HTML+CSS和DIV怎么实现排版布局

发布时间:2020-09-28 17:16:11 作者:小新
来源:亿速云 阅读:185

这篇文章给大家分享的是有关HTML+CSS和DIV怎么实现排版布局的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。

HTML CSS + div实现排版布局

1.网页可以看成是由一个一个“盒子”组成,如图:

HTML+CSS和DIV怎么实现排版布局

由上图可以看出,页面分为上(网站导航)、中、下(版权声明)三个部分,
中间部分又分为左(商品分类)、中(主要部分)、右,这些版块就像一个个
的盒子,这些"盒子"中放置着各种内容,页面就是由这些"盒子"拼凑起来

HTML+CSS和DIV怎么实现排版布局

单列布局案例:

代码如下:
<!doctype html>
<html>
    <head>
        <meta charset="utf-8"/>
        <title>单列布局</title>
    </head>
    <style>
        body{
            margin:0;
        }
        .box{
            width:960px;
            margin:0 auto;
        }
        .box .header{
            height:120px;
            border:1px solid #f00;
            line-height:120px;
        }
        .box .main{
            height:300px;
            border:1px solid #0f0;
            line-height:300px;
        }
        .box .footer{
            height:100px;
            border:1px solid #00f;
            line-height:100px;
        }
        p{
            text-align:center;
        }
    </style>    
    <body>        
        <p class="box">
            <p class="header">头部</p>
            <p class="main">主题</p>
            <p class="footer">底部</p>
        </p>            
    </body>
</html>
运行结果:

HTML+CSS和DIV怎么实现排版布局

双列布局案例:

代码如下:
<!doctype html>
<html>
    <head>
        <meta charset="utf-8"/>
        <title>双列布局</title>
    </head>
    <style>
        body{
        margin:0;
        }
        .box{
            width:80%;
            margin:0 auto;
            overflow:hidden;
        }
        .box .left{
            width:30%;
            height:400px;
            background-color:#0f0;
            float:left;
        }
        .box .right{
            width:70%;
            height:400px;
            background-color:#f00;
            float:left;
        }
    </style>
    <body>        
        <p class="box">
            <p class="left"></p>
            <p class="right"></p>
        </p>        
    </body>
</html>
运行结果如下图:

HTML+CSS和DIV怎么实现排版布局

三列布局案例:

代码如下:
<!doctype html>
<html>
    <head>
        <meta charset="utf-8"/>
        <title>三列布局</title>
    </head>
    <style>
    body{
        margin:0;
    }
    .box{
        width:960px;
        margin:0 auto;
        position:relative;
    }
    .box .left{
        width:200px;
        height:400px;
        background-color:#0f0;
        position:absolute;
    }
    .box .center{
        height:400px;
        background-color:#00f;
        margin:0 300px 0 200px;
    }
    .box .right{
        width:300px;
        height:400px;
        background-color:#f00;
        position:absolute;
        right:0;
        top:0;
    }
    </style>
    <body>        
        <p class="box">
            <p class="left"></p>
            <p class="center"></p>
            <p class="right"></p>
        </p>            
    </body>
</html>
运行结果如下图:

HTML+CSS和DIV怎么实现排版布局

混合布局案例:

代码如下:
<!doctype html>
<html>
    <head>
        <meta charset="utf-8"/>
        <title>混合布局</title>
    </head>
    <style>
    body{
        margin:0;
    }
    .box{
        width:960px;
        margin:0 auto;
    }
    .header{
        height:120px;
        background-color:#ddd;    
    }
    .main{
        height:400px;
        background-color:#f00;
        position:relative;
    }

    .main .left{
        width:200px;
        height:400px;
        position:absolute;
        left:0;
        top:0;
        background-color:#0fccaa;
    }
    .main .center{
        height:400px;
        margin:0 305px 0 205px;
        background-color:#123456;
    }

    .main .right{
        width:300px;
        height:400px;
        position:absolute;
        right:0;
        top:0;
        background-color:#ff0;
    }
    .footer{
        height:80px;
        background-color:#ddd;
    }
    </style>
    <body>        
        <p class="box">
            <p class="header"></p>
            <p class="main">
                <p class="left"></p>
                <p class="center"></p>
                <p class="right"></p>        
            </p>
            <p class="footer"></p>
        </p>    
    </body>
</html>
运行结果如下图:

HTML+CSS和DIV怎么实现排版布局

感谢各位的阅读!关于HTML+CSS和DIV怎么实现排版布局就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!

推荐阅读:
  1. 2)前端的css排版布局
  2. div左右布局

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

html css %d

上一篇:怎么用canvas实现在线签名的示例代码

下一篇:详解基于Node.js的HTTP/2 Server实践

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》