CSS学习笔记8:实操——运用浮动简单布局网页

学习完浮动,我们就可以利用已学的知识做一个初级的网页布局了。下面我们布局成下图所示的网页:
如图:
这里写图片描述

思路:由大到小拆分盒子

  • 1.先看上下分成3大部分,头部,中间和尾部3个大盒子。三个大盒子按照标准文档流上下排列,无需浮动。

  • 2.拆分头部第一个大盒子:头部可拆分成1个红色盒子和2个绿色盒子。红色盒子左浮动,2个绿色盒子右浮动。思考:为什么较长的绿色盒子没有贴在较短的绿色盒子后面,与之并排在第一行?那是因为,第一行绿色盒子和红色盒子中间的空间较小,较长的绿色盒子自动跌落贴右墙。
    3.拆分中间的盒子,中间的盒子分为左右2个小盒子,并使两个盒子左浮动。右边的盒子右可继续拆分为上下两个盒子,无需浮动。上面的盒子可拆分成左右两个盒子,都左浮动。左边的盒子可拆分3个天蓝的盒子,不浮动。思考为什么天蓝色的3个盒子不需要浮动?因为,天蓝色的父亲盒子已经左浮动了。

代码示例:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        .header{
            width: 970px;
            height: 103px;
            /*自动居中*/
            margin: 0 auto;
        }
        .header .logo{
            float: left;
            width: 277px;
            height: 103px;
            background-color: red;
        }
        .header .language{
            float: right;
            width: 137px;
            height: 49px;
            background-color: green;
            margin-bottom: 8px;
        }
        .header .nav{
            float: right;
            width: 679px;
            height: 46px;
            background-color: green;
        }

        .content{
            width: 970px;
            height: 435px;
            margin: 0 auto;
            margin-top: 10px;
        }
        .content .banner{
            float: left;
            width: 310px;
            height: 435px;
            background-color: gold;
            margin-right: 10px;
        }
        .content .rightPart{
            float: left;
            width: 650px;
            height: 435px;
        }
        .content .rightPart .main{
            width: 650px;
            height: 400px;
            margin-bottom: 10px;
        }
        .content .rightPart .links{
            width: 650px;
            height: 25px;
            background-color: blue;
        }
        .content .rightPart .main .news{
            float: left;
            width: 450px;
            height: 400px;
        }
        .content .rightPart .main .hotpic{
            float: left;
            width: 190px;
            height: 400px;
            background-color: purple;
            margin-left: 10px;
        }
        .content .rightPart .main .news .news1{
            width: 450px;
            height: 240px;
            background-color: skyblue;
            margin-bottom: 10px;
        }
        .content .rightPart .main .news .news2{
            width: 450px;
            height: 110px;
            background-color: skyblue;
            margin-bottom: 10px;
        }
        .content .rightPart .main .news .news3{
            width: 450px;
            height: 30px;
            background-color: skyblue;
        }
        .footer{
            width: 970px;
            height: 35px;
            background-color: navy;
            margin: 0 auto;
            margin-top: 10px;
        }
    </style>
</head>
<body>
    <!-- 头部 -->
    <div class="header">
        <div class="logo">logo</div>
        <div class="language">语言选择</div>
        <div class="nav">导航条</div>
    </div>

    <!-- 主要内容 -->
    <div class="content">
        <div class="banner">大广告</div>
        <div class="rightPart">
            <div class="main">
                <div class="news">
                    <div class="news1"></div>
                    <div class="news2"></div>
                    <div class="news3"></div>
                </div>
                <div class="hotpic"></div>
            </div>
            <div class="links"></div>
        </div>
    </div>

    <!-- 页尾 -->
    <div class="footer"></div>
</body>
</html>

运行代码网页效果(哈哈哈,颜色差异请忽略~):
这里写图片描述

注意:为了便于更容易看到效果,可在拆分大盒子之前,给大盒子设置一个背景颜色,等效果做好,再去掉。

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
第1关的任务是运用HTML5的语义化元素设计一个包含头部标题和文章内容的文章区。在这个任务中,我们需要使用header元素来表示文章区的头部。 在HTML5中,header元素用于表示页面或一个区块的头部部分。它通常包含页面的标题或区块的标题。在这个任务中,我们可以使用header元素来包含文章的标题。 下面是一个示例代码,展示了如何使用header元素来表示文章区的头部,并设置了一个茗茶推荐的标题:"茗茶推荐——祁门红茶": ``` <!DOCTYPE html> <html> <head> <title>页面结构</title> <style type="text/css"> header{ border-bottom:4px double #eee; text-align:center; font-size :20px } </style> </head> <body> <!-- ********* Begin ******* --> <article> <header><h3>茗茶推荐——祁门红茶</h3></header> <p>祁门红茶,茶叶原料选用当地的中叶,中生种茶树制作,是中国历史名茶,著名红茶精品。</p> </article> <!-- ********* End ********* --> </body> </html> ``` 通过设置header元素的样式,我们可以为文章区的头部添加一条底边,并设置居中对齐和字体大小。同时,我们在header元素内部使用h3标签来显示文章标题。 希望这个回答对你有帮助,祝你成功!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [EduCoder-Web程序设计基础-html5—结构元素-第2关:header元素和article元素的应用](https://blog.csdn.net/weixin_51402180/article/details/121688659)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值