首页 > 其他分享 >前端学习-HTML/CSS刷题笔记03

前端学习-HTML/CSS刷题笔记03

时间:2024-01-21 12:11:28浏览次数:39  
标签:03 solid 100px 1px HTML black border CSS left

1 布局

单列布局

单列布局是将头部、内容区、底部在页面上垂直排列,是非常实用的一种布局方式。主要对三个区域的宽度进行统一,然后通过设置自动外边距进行居中。

    <!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;
                box-sizing: border-box;
            }
            body {
                width: 500px;
            }
            header,
            section,
            footer {
                margin: 10px auto;
                width: 360px;
                border: 1px solid black;
            }

            header,
            footer {
                height: 32px;
            }
        </style>
    </head>
    <body>
        <header></header>
        <section><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /></section>
        <footer></footer>
    </body>
    </html>

双列布局

BFC

参考链接

  • 什么是BFC:具有 BFC 特性的元素可以看作是隔离了的独立容器,容器里面的元素不会在布局上影响到外面的元素,并且 BFC 具有普通容器所没有的一些特性。
  • 什么可以使元素具有BFC特性:
    • body 根元素
    • 浮动元素:float 除 none 以外的值
    • 绝对定位元素:position (absolute、fixed)
    • display 为 inline-block、table-cells、flex
    • overflow 除了 visible 以外的值 (hidden、auto、scroll)
  • BFC 可以包含浮动的元素(清除浮动)
  • 子元素没有浮动时

  • 子元素浮动、父元素没有触发BFC

  • 子元素浮动、父元素触发BFC

    <!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>
            .out {
                border: 1px solid #000;
                overflow: hidden;
            }

            .in {
                width: 100px;
                height: 100px;
                background-color: #eee;
                float: left;
            }
        </style>
    </head>
    <body>
        <div class="out">
            <div class="in"></div>
        </div>
    </body>
    </html>
  • 实现两列布局-BFC
    • 父元素触发BFC
    • 子元素1浮动,子元素2不浮动,父元素高度取两个子元素中高的一个
    • 如下例,子元素1会覆盖子元素2,可对子元素2使用margin-left: 100px;
    <!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;
                box-sizing: border-box;
            }
            .container {
                border: 1px solid black;
                overflow: hidden;
            }
            .left {
                border: 1px solid black;
                float: left;
                width: 100px;
                background-color: pink;
            }
            .right {
                margin-left: 100px;
                background-color: greenyellow;
            }
        </style>
    </head>
    <body>
        <section class="container">
            <article class="left"><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /></article>
            <article class="right"><br /></article>
        </section>
    </body>
    </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;
                box-sizing: border-box;
            }
            .container {
                position: relative;
            }
            .left {
                border: 1px solid black;
                position: absolute;
                left: 0;
                width: 100px;
            }
            .right {
                border: 1px solid black;
                position: absolute;
                right: 0;
                left: 100px;
            }
        </style>
    </head>
    <body>
        <section class="container">
            <article class="left"><br /><br /><br /><br /></article>
            <article class="right"><br /><br /><br /></article>
        </section>
    </body>
    </html>
  • 实现两列布局-flex
    <!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;
                box-sizing: border-box;
            }
            .container {
                border: 1px solid black;
                display: flex;
            }
            .left {
                border: 1px solid black;
                width: 100px;
            }
            .right {
                border: 1px solid greenyellow;
                flex: 1;
            }
        </style>
    </head>
    <body>
        <section class="container">
            <article class="left"><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /></article>
            <article class="right"></article>
        </section>
    </body>
    </html>
  • 实现两列布局-grid
    <!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;
                box-sizing: border-box;
            }
            .container {
                border: 1px solid black;
                display: grid;
                grid-template-columns: 100px 1fr;
            }
            .left {
                border: 1px solid black;
            }
        </style>
    </head>
    <body>
        <section class="container">
            <article class="left"><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /></article>
            <article class="right"></article>
        </section>
    </body>
    </html>
  • 实现三列布局-浮动
    • 浮动元素要写在内容元素之前,否则布局是混乱的
    • 优点:兼容性好、实现简单
    • 缺点:要清除浮动
    • 为防止内容元素被遮挡,需要给内容元素添加margin
    <!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;
                box-sizing: border-box;
            }
            .container {
                border: 1px solid black;
                overflow: hidden;
            }
            .left {
                border: 1px solid black;
                background-color: pink;
                float: left;
                width: 100px;
            }
            .right {
                border: 1px solid black;
                background-color: greenyellow;
                float: right;
                width: 100px;
            }
            .center {
                background-color: skyblue;
                margin: 0 100px;
            }
        </style>
    </head>
    <body>
        <section class="container">
            <article class="left"><br /><br /><br /></article>
            <article class="right"><br /><br /><br /></article>
            <article class="center">aaaaaaaaaaaaaa</article>
        </section>
    </body>
    </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;
                box-sizing: border-box;
            }
            .container {
                position: relative;
            }
            .left {
                position: absolute;
                border: 1px solid black;
                left: 0;
                width: 100px;
            }
            .center {
                position: absolute;
                border: 1px solid black;
                left: 100px;
                right: 100px;
            }
            .right {
                position: absolute;
                border: 1px solid black;
                right: 0;
                /* width: 100px; */
            }
        </style>
    </head>
    <body>
        <section class="container">
            <article class="left"><br /><br /></article>
            <article class="center"><br /><br /><br /></article>
            <article class="right"><br /><br /><br /><br /></article>
        </section>
    </body>
    </html>
  • 实现三列布局-flex
    <!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;
                box-sizing: border-box;
            }
            .container {
                display: flex;
            }
            .left {
                border: 1px solid black;
                width: 100px;
            }
            .center {
                border: 1px solid black;
                flex: 1;
            }
            .right {
                border: 1px solid black;
                width: 100px;
            }
        </style>
    </head>
    <body>
        <section class="container">
            <article class="left"><br /><br /></article>
            <article class="center"><br /><br /><br /></article>
            <article class="right"><br /><br /><br /><br /></article>
        </section>
    </body>
    </html>
  • 实现三列布局-grid
    <!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;
                box-sizing: border-box;
            }
            .container {
                display: grid;
                grid-template-columns: 100px 1fr 100px;
            }
            .left {
                border: 1px solid black;
                /* width: 100px; */
            }
            .center {
                border: 1px solid black;
                /* flex: 1; */
            }
            .right {
                border: 1px solid black;
                /* width: 100px; */
            }
        </style>
    </head>
    <body>
        <section class="container">
            <article class="left"><br /><br /></article>
            <article class="center"><br /><br /><br /></article>
            <article class="right"><br /><br /><br /><br /></article>
        </section>
    </body>
    </html>

三列布局-圣杯布局

这篇讲的很清楚,圣杯布局就是将基本布局之后使用向左浮动,middle栏留出两边位置,然后使用相对定位将左右两栏通过margin-left定位到相应位置。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }
        .content {
            overflow: hidden;
            padding: 0 100px;
        }
        .header {
            background-color: pink;
        }
        .left {
            background-color: greenyellow;
            width: 100px;
            float: left;
            position: relative;
            margin-left: -100%;
            right: 100px;
        }
        .middle {
            background-color: darkorange;
            width: 100%;
            float: left;
            min-width: 100px;
        }
        .right {
            background-color: darkgreen;
            width: 100px;
            float: left;
            margin-right: -100px;
        }
        .footer {
            background-color: skyblue;
        }
    </style>
</head>
<body>
    <div class="header">header</div>
    <div class="content wrapper">
        <div class="middle">middle</div>
        <div class="left">left</div>
        <div class="right">right</div>
    </div>
    <div class="footer">footer</div>
</body>
</html>

双飞翼布局

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }
        .header {
            background-color: pink;
        }
        .left {
            background-color: greenyellow;
            width: 100px;
            float: left;
            margin-left: -100%;
        }
        .middle {
            background-color: darkorange;
            float: left;
            width: 100%;
        }
        /* 直接在.middle上设置padding,布局会乱 */
        .main-wrapper {
            padding: 0 100px;
        }
        .right {
            background-color: darkgreen;
            width: 100px;
            float: left;
            margin-left: -100px;
        }
        .footer {
            background-color: skyblue;
            clear: both;
        }
    </style>
</head>
<body>
    <div class="header">header</div>
    <div class="main middle"><div class="main-wrapper">middle</div></div>
    <div class="left">left</div>
    <div class="right">right</div>
    <div class="footer">footer</div>
</body>
</html>

标签:03,solid,100px,1px,HTML,black,border,CSS,left
From: https://www.cnblogs.com/ayubene/p/17969823

相关文章

  • pd.read_csv( parse_dates=True) AttributeError: 'DatetimeIndex' object has no a
    pandas读取文件的read_csv()方法的parse_dates,index_col参数介绍 pd.read_csv(parse_dates=True)    data=pd.read_csv(f'datasets/{name}.csv',index_col='date',parse_dates=True)dt.weekofyear.to_numpy(),df_asset[“week_of_year”]=df_asset.index.we......
  • CSS颜色
    1、RGB和RGBA  2、HEX或者HEXA(十六进制) HSL和HSLA  ......
  • Luogu P1042 [NOIP2003 普及组] 乒乓球
    [NOIP2003普及组]乒乓球\(link\)题目背景国际乒联现在主席沙拉拉自从上任以来就立志于推行一系列改革,以推动乒乓球运动在全球的普及。其中\(11\)分制改革引起了很大的争议,有一部分球员因为无法适应新规则只能选择退役。华华就是其中一位,他退役之后走上了乒乓球研究工作,意图......
  • AT_abc303_d
    看到本题,很容易想到贪心,对每一段相同的子串计算最小代价。但这种思路的评测结果显示有\(3\)个测试点WA了,因此解法错误。既然贪心行不通,我们不妨使用dp,对每一位进行分类讨论并求最小耗时。设\(dp_{i,j}\)表示Capslock状态为\(j\)时(\(j\)为\(0\)或\(1\),\(0\)表示熄......
  • HTML基础
    HTML标准结构标签的语义Meta元信息META标签,是在HTML网页源代码中一个重要的html标签。META标签用来描述一个HTML网页文档的属性,例如作者、日期和时间、网页描述、关键词、页面刷新等。META标签元素可提供有关页面的元信息(meta-information),比如针对搜索引擎和更新频......
  • HTML入门
    #HTML入门HTML基础超文本标记语言(HyperTextMarkupLanguage,简称:HTML)是一种用于创建网页的标准标记语言。HTML-----用来描述网页的一种语言```<head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"......
  • GYM102596L Yosupo's Algorithm【分治,支配对】
    给定平面上\(2n\)个点,每个点有坐标\((x_i,y_i)\),权值\(w_i\)及颜色\(c_i\)。所有点满足:若\(c_i=0\),则\(x_i<0\);若\(c_i=1\),则\(x_i>0\)。\(q\)次查询,每次给定\(L_i,R_i\),你需要选择两个点\(i,j\)满足如下条件:\(c_i=0,c_j=1\)。\(x_i<L,x_j>R\)或\(x_......
  • Previously on Assassin's Creed Ⅱ
    MynameisDesmondMiles.I'maprisonerofwar.AwarIneverknewexisted,wagedbytwogroupsIneverthoughtwerereal–TemplarsandAssassins.TheAnimusshowedmethetruth.ThethingsI'veseen,thethingsI'vebeen.Athousandyears......
  • 惠海H6203L 150V1.5A高精度低功耗降压恒压型
    产品描述:H6203L是一种内置150V耐压MOS,支持输高达120V的高压降压开关控制器,支持输出电压最低可调至3.3V,可以向负载提供1.5A的连续电流及最高4A的瞬间电流,采用ESOP-8封装,芯片底部设计有功率散热焊盘,连接芯片的VIN输入端及内置MOS漏极,可以有效的帮助芯片加大散热。产品特征:转换效率最......
  • openeuler2203升级openssh9.4p1解决漏洞问题
    openeuler2203升级openssh9.4p1解决漏洞问题 1,使用rpmbuild将tar包打成rpm包,不喜欢编译升级的,使用RPM升级就方便多了。想使用openssh的源码包编译安装的,参考这里:OpenSSH-9.4p1(linuxfromscratch.org) 2,准备编译环境[root@centos7-31~]#  yuminstallrpm-buildzlib......