博客列表 >课后作业-5-页面布局-2019/09/05 17:30提交

课后作业-5-页面布局-2019/09/05 17:30提交

Doctor_Zhong
Doctor_Zhong原创
2019年09月05日 17:53:58673浏览


实例

<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="style01.css">
    <title>页面布局</title>
    <style>
        code {
            display: block;
            background-color: #000000;
            color: #fff;
            width: 600px;
            margin-left: 2em;
        }
        
        header,
        div {
            border: 1px dotted green;
            box-sizing: border-box;
        }
        
        .html,
        header,
        .container {
            width: 100%;
            float: left;
            clear: both;
            overflow: hidden;
            margin: 1em auto;
        }
        
        header {
            background-color: rgba(200, 200, 0, 0.1);
        }
        
        .container {
            background-color: rgba(0, 0, 360, 1);
        }
        /* **绝对定位布局样式** */
        
        #container_1 {
            height: 700px;
        }
        
        #layout_1 {
            position: relative;
            margin: 10px 5%;
            height: 700px;
            background-color: yellow;
        }
        
        .header,
        .main,
        .footer,
        .left,
        .center,
        .right {
            position: absolute;
        }
        
        .header {
            left: 0;
            top: 0;
            width: 100%;
            height: 50px;
            background-color: lightgoldenrodyellow;
        }
        
        .main {
            left: 0;
            top: 50px;
            width: 100%;
            height: 600px;
            background-color: lightblue;
        }
        
        .footer {
            left: 0;
            bottom: 0;
            width: 100%;
            height: 50px;
            background-color: lightgrey;
        }
        
        .left {
            left: 0;
            top: 0;
            width: 20%;
            height: 100%;
            background-color: lightslategray;
        }
        
        .center {
            left: 20%;
            top: 0;
            width: 80%;
            height: 100%;
            background-color: darkseagreen;
        }
        
        .right {
            right: 0;
            top: 0;
            width: 20%;
            height: 100%;
            background-color: darkgrey;
        }
        /* **浮动布局样式** */
        
        #container_2 {
            width: 100%;
            float: left;
            clear: both;
        }
        
        #layout_2 {
            position: relative;
            margin: 10px 5%;
            background-color: yellow;
        }
        
        .header-f {
            width: 100%;
            height: 60px;
            background-color: lightseagreen;
            float: left;
        }
        
        .main-f {
            width: 100%;
            height: 490px;
            /* ????height如何设置自动撑开???? */
            background-color: lightcyan;
            float: left;
        }
        
        .footer-f {
            width: 100%;
            height: 50px;
            background-color: lightseagreen;
        }
        
        .left-f,
        .center-f,
        .right-f,
        .footer-f {
            float: left;
        }
        
        .left-f {
            width: 20%;
            height: 100%;
            background-color: lightgoldenrodyellow;
        }
        
        .center-f {
            width: 60%;
            height: 100%;
            background-color: lightblue;
        }
        
        .right-f {
            width: 20%;
            height: 100%;
            background-color: lightgrey;
        }
    </style>
</head>
<!-- 实例演示三列布局的实现原理( 绝对定位实现, 浮动定位实现) -->

<body>
    <header>
        <div>
            <p>说明:</p>
            <p>为了在同一个页面实现两种布局的对比,以下用div.container(蓝色背景)模拟body标签</p>
            <p></p>
        </div>
    </header>
    <!-- .html模拟html标签 -->
    <div class="html">
        <div class="clear_both" style="width: 100%;height: 0;border: 0px solid red;"></div>
        <!-- 绝对定位实现 -->
        <div class="container" id="container_1">
            <div class="layout" id="layout_1">
                <div class="header">
                    <h2>1. 绝对定位实现3列布局
                        <span>[header]</span>
                    </h2>
                </div>
                <div class="main">
                    <div class="left">left</div>
                    <div class="center">center</div>
                    <div class="right">right</div>
                </div>
                <div class="footer">footer</div>
            </div>
        </div>
        <!-- .container结束 -->
        <div class="text">
            <p>html code:</p>
            <code><pre>
&lt;!-- 绝对定位实现 -->
&lt;div class="container" id="container_1">
    &lt;div class="layout" id="layout_1">
        &lt;div class="header">
            &lt;h2>1. 绝对定位实现3列布局
                &lt;span>[header]&lt;/span>
            &lt;/h2>
        &lt;/div>
        &lt;div class="main">
            &lt;div class="left">left&lt;/div>
            &lt;div class="center">center&lt;/div>
            &lt;div class="right">right&lt;/div>
        &lt;/div>
        &lt;div class="footer">footer&lt;/div>
    &lt;/div>
&lt;/div>
&lt;!-- .container结束 -->
            </pre></code>
            <p>css code:</p>
            <code><pre>
/* **绝对定位布局样式** */

#container_1 {
    height: 700px;
}

#layout_1 {
    position: relative;
    margin: 10px 5%;
    height: 700px;
    background-color: yellow;
}

.header,
.main,
.footer,
.left,
.center,
.right {
    position: absolute;
}

.header {
    left: 0;
    top: 0;
    width: 100%;
    height: 50px;
    background-color: lightgoldenrodyellow;
}

.main {
    left: 0;
    top: 50px;
    width: 100%;
    height: 600px;
    background-color: lightblue;
}

.footer {
    left: 0;
    bottom: 0;
    width: 100%;
    height: 50px;
    background-color: lightgrey;
}

.left {
    left: 0;
    top: 0;
    width: 20%;
    height: 100%;
    background-color: lightslategray;
}

.center {
    left: 20%;
    top: 0;
    width: 80%;
    height: 100%;
    background-color: darkseagreen;
}

.right {
    right: 0;
    top: 0;
    width: 20%;
    height: 100%;
    background-color: darkgrey;
}
            </pre></code>
        </div>


        <div class="clear_both" style="width: 100%;height: 0;border: 0px solid red;"></div>

        <!-- 浮动定位实现 -->
        <div class="container" id="container_2">
            <div class=" layout " id="layout_2">
                <div class="header-f ">
                    <h2>2. 浮动定位实现3列布局[header-f]</h2>
                </div>
                <div class="main-f ">
                    <div class="left-f ">[left-f]</div>
                    <div class="center-f ">[center-f]</div>
                    <div class="right-f ">[right-f]</div>
                </div>
                <div class="footer-f ">[footer-f]</div>
            </div>
        </div>
        <!-- .container结束 -->
        <div class="text">
            <p>html code:</p>
            <code><pre>
&lt;!-- 浮动定位实现 -->
&lt;div class="container" id="container_2">
    &lt;div class=" layout " id="layout_2">
        &lt;div class="header-f ">
            &lt;h2>2. 浮动定位实现3列布局[header-f]&lt;/h2>
        &lt;/div>
        &lt;div class="main-f ">
            &lt;div class="left-f ">[left-f]&lt;/div>
            &lt;div class="center-f ">[center-f]&lt;/div>
            &lt;div class="right-f ">[right-f]&lt;/div>
        &lt;/div>
        &lt;div class="footer-f ">[footer-f]&lt;/div>
    &lt;/div>
&lt;/div>
&lt;!-- .container结束 -->
                            </pre></code>
            <p>css code:</p>
            <code><pre>
/* **浮动布局样式** */

#container_2 {
    width: 100%;
    float: left;
    clear: both;
}

#layout_2 {
    position: relative;
    margin: 10px 5%;
    background-color: yellow;
}

.header-f {
    width: 100%;
    height: 60px;
    background-color: lightseagreen;
}

.main-f {
    width: 100%;
    height: 490px;
    /* ????height如何设置自动撑开???? */
    background-color: lightcyan;
    float: left;
}

.footer-f {
    width: 100%;
    height: 50px;
    background-color: lightseagreen;
}

.header-f,
.left-f,
.center-f,
.right-f,
.footer-f {
    float: left;
}

.left-f {
    width: 20%;
    height: 100%;
    background-color: lightgoldenrodyellow;
}

.center-f {
    width: 60%;
    height: 100%;
    background-color: lightblue;
}

.right-f {
    width: 20%;
    height: 100%;
    background-color: lightgrey;
}
            </pre></code>
        </div>


        <div class="clear_both" style="width: 100%;height: 0;border: 0px solid red;"></div>

    </div>
    <!-- .html结束 -->
</body>


</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议