HTML(Basic) Chapter5(Pink)网页浮动以及几种常用的布局方式


1.网页布局的基础知识

浮动元素的特性

  1. 浮动元素会脱离标准流(脱标)
  2. 浮动的元素会议行内显示与元素的顶部对齐
  3. 浮动的元素会具有行内块元素的特性
  4. 多个块的横向元素使用浮动,创建浮动会一直移到边缘

脱标

  1. 脱离标准流的控制指脱离了普通的标准流(浮)
  2. 已经与原来的标准流不是一个级别的东西
  3. 原来的标准流就会补上原来的盒子

行内块元素的特性

  • 任何的元素都可以浮动,不管原先是什么模式下的元素,天机浮动后都具有行内块元素的特性

通栏

  • 和浏览器一样宽,即不需要指定高度

浮动布局的注意点

  • 一般是先有父元素,然后后面的子元素使用浮动
  • 一般的话兄弟之间的元素都会一起浮动,如果不浮动则div大盒子会独占一行,然后其兄弟盒子会在其下面浮动显示
  • 浮动的盒子会压住后面的标准流,但是不会影响前面没有浮动的标准流

HTML源代码(浮动练习1.html)

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        li {
            list-style: none;
        }

        .box {
            height: 285px;
            width: 1226px;
            background-color: pink;
            margin: 0 auto;
        }

        .box li {
            float: left;
            width: 296px;
            height: 285px;
            background-color: purple;
            margin-right: 14px;
        }

        .box .last {
            margin-right: 0px;
        }
    </style>
</head>

<body>
    <ul class="box">
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li class="last">4</li>
    </ul>
</body>

</html>

最终效果

最终效果


2.小米商城手机模块页面布局

HTML源代码(浮动练习2手机.html)

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>手机练习模块</title>
    <style>
        .box {
            width: 1226px;
            height: 615px;
            background-color: pink;
            margin: 0 auto;
        }

        .left {
            float: left;
            width: 234px;
            height: 615px;
            background-color: purple;
        }

        .right {
            float: left;
            width: 992px;
            height: 615px;
            background-color: skyblue;
        }

        /* 子代选择器只选择亲儿子 */
        .right>div {
            float: left;
            width: 234px;
            height: 300px;
            background-color: pink;
            margin-left: 14px;
            margin-bottom: 14px;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="left">左青龙</div>
        <div class="right">
            <div>1</div>
            <div>2</div>
            <div>3</div>
            <div>4</div>
            <div>5</div>
            <div>6</div>
            <div>7</div>
            <div>8</div>
        </div>
    </div>
</body>

</html>

最终效果

7


3.开发中比较常用的页面布局

HTML源代码(开发常用.html)

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>常用的网页布局</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .top {
            height: 50px;
            background-color: gray;
        }

        .banner {
            width: 980px;
            height: 150px;
            background-color: gray;
            margin: 10px auto;
        }

        .box {
            width: 980px;
            margin: 0 auto;
            height: 300px;
            background-color: pink;
        }

        li {
            list-style: none;
        }

        .box li {
            float: left;
            width: 237px;
            height: 300px;
            background-color: gray;
            margin-right: 10px;
        }

        .box .last {
            margin-right: 0px;
        }

        /* 只要是通栏的盒子(和浏览器一样宽)则不需要指定宽度 */
        .footer {
            height: 200px;
            background-color: gray;
            margin-top: 20px;
        }
    </style>
</head>

<body>
    <div class="top">top</div>
    <div class="banner">banner</div>
    <div class="box">
        <ul>
            <li>1</li>
            <li>2</li>
            <li>3</li>
            <li class="last">4</li>
        </ul>
    </div>
    <div class="footer">footer</div>
</body>

</html>

网页布局最终效果

8


写在最后

注:上述笔记均来自黑马程序员pink老师前端入门教程,零基础必看的h5(html5)+css3+web前端视频教程 这一课程的学习记录,主要供自己的学习分享

各位看官,都看到这里了,麻烦动动手指头给博主来个点赞8,您的支持作者最大的创作动力哟! <(^-^)>
才疏学浅,若有纰漏,恳请斧正
本文章仅用于各位同志作为学习交流之用,不作任何商业用途,若涉及版权问题请速与作者联系,望悉知

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值