HTML

HTML 和 CSS

  • 页面布局

  • css盒模型

  • BFC

页面布局

左右固定,中间自适应.png

有5中可以解决:

​ 第一种:浮动


<section class="layout float">

      <style media="screen">

      .layout.float .left{

        float:left;

        width:300px;

        background: red;

      }

      .layout.float .center{

        background: yellow;

      }

      .layout.float .right{

        float:right;

        width:300px;

        background: blue;

      }

      </style>

      <h1>三栏布局</h1>

      <article class="left-right-center">

        <div class="left"></div>

        <div class="right"></div>

        <div class="center">

          <h2>浮动解决方案</h2>

          1.这是三栏布局的浮动解决方案;

          2.这是三栏布局的浮动解决方案;

          3.这是三栏布局的浮动解决方案;

          4.这是三栏布局的浮动解决方案;

          5.这是三栏布局的浮动解决方案;

          6.这是三栏布局的浮动解决方案;

        </div>

      </article>

    </section>

第二种:定位


<!-- 绝对布局 -->

    <section class="layout absolute">

      <style>

        .layout.absolute .left-center-right>div{

          position: absolute;

        }

        .layout.absolute .left{

          left:0;

          width: 300px;

          background: red;

        }

        .layout.absolute .center{

          left: 300px;

          right: 300px;

          background: yellow;

        }

        .layout.absolute .right{

          right:0;

          width: 300px;

          background: blue;

        }

      </style>

      <h1>三栏布局</h1>

      <article class="left-center-right">

        <div class="left"></div>

        <div class="center">

          <h2>绝对定位解决方案</h2>

          1.这是三栏布局的浮动解决方案;

          2.这是三栏布局的浮动解决方案;

          3.这是三栏布局的浮动解决方案;

          4.这是三栏布局的浮动解决方案;

          5.这是三栏布局的浮动解决方案;

          6.这是三栏布局的浮动解决方案;

        </div>

        <div class="right"></div>

      </article>

    </section>

第三种:flex布局


<!-- flexbox布局 -->

    <section class="layout flexbox">

      <style>

        .layout.flexbox{

          margin-top: 110px;

        }

        .layout.flexbox .left-center-right{

          display: flex;

        }

        .layout.flexbox .left{

          width: 300px;

          background: red;

        }

        .layout.flexbox .center{

          flex:1;

          background: yellow;

        }

        .layout.flexbox .right{

          width: 300px;

          background: blue;

        }

      </style>

      <h1>三栏布局</h1>

      <article class="left-center-right">

        <div class="left"></div>

        <div class="center">

          <h2>flexbox解决方案</h2>

          1.这是三栏布局的浮动解决方案;

          2.这是三栏布局的浮动解决方案;

          3.这是三栏布局的浮动解决方案;

          4.这是三栏布局的浮动解决方案;

          5.这是三栏布局的浮动解决方案;

          6.这是三栏布局的浮动解决方案;

        </div>

        <div class="right"></div>

      </article>

    </section>

第四种:表格布局


<!-- 表格布局 -->

    <section class="layout table">

      <style>

        .layout.table .left-center-right{

          width:100%;

          height: 100px;

          display: table;

        }

        .layout.table .left-center-right>div{

          display: table-cell;

        }

        .layout.table .left{

          width: 300px;

          background: red;

        }

        .layout.table .center{

          background: yellow;

        }

        .layout.table .right{

          width: 300px;

          background: blue;

        }

      </style>

      <h1>三栏布局</h1>

      <article class="left-center-right">

        <div class="left"></div>

        <div class="center">

          <h2>表格布局解决方案</h2>

          1.这是三栏布局的浮动解决方案;

          2.这是三栏布局的浮动解决方案;

          3.这是三栏布局的浮动解决方案;

          4.这是三栏布局的浮动解决方案;

          5.这是三栏布局的浮动解决方案;

          6.这是三栏布局的浮动解决方案;

        </div>

        <div class="right"></div>

      </article>

    </section>

第五种:网格布局(CSS最新增的,类似于bootstrap的栅格系统)


<!-- 网格布局 -->

    <section class="layout grid">

      <style>

        .layout.grid .left-center-right{

          width:100%;

          display: grid;

          grid-template-rows: 100px;

          grid-template-columns: 300px auto 300px;

        }

        .layout.grid .left-center-right>div{

        }

        .layout.grid .left{

          width: 300px;

          background: red;

        }

        .layout.grid .center{

          background: yellow;

        }

        .layout.grid .right{

          background: blue;

        }

      </style>

      <h1>三栏布局</h1>

      <article class="left-center-right">

        <div class="left"></div>

        <div class="center">

          <h2>网格布局解决方案</h2>

          1.这是三栏布局的浮动解决方案;

          2.这是三栏布局的浮动解决方案;

          3.这是三栏布局的浮动解决方案;

          4.这是三栏布局的浮动解决方案;

          5.这是三栏布局的浮动解决方案;

          6.这是三栏布局的浮动解决方案;

        </div>

        <div class="right"></div>

      </article>

    </section>

若高度不给,那么高度能自适应的只有 flex 布局和 表格布局,网格布局了,其他则不可以

CSS盒模型

概念:有2种,标准模型 + IE模型

css盒模型-标准模型.png
css盒模型-IE模型.png

css如何设置这2种模型

  • box-sizing:border-box; IE模型

  • box-sizing:content-box; 标准模型(默认)

js如何设置获取盒模型对应的宽和高:

  • dom.style.width/height 这个只能取到内联样式的宽高

  • dom.getBoundingClientRect().width/height 这个也能拿到,有4个值,还有2个是距离顶部和左边的距离

BFC(边距重叠解决方案)

  • 概念:块级格式化上下文 ,它决定了元素如何对其内容进行定位,以及与其他元素的关系和相互作用

  • 原理:如果一个元素符合了成为BFC的条件,该元素内部元素的布局和定位就和外部元素互不影响(除非内部的盒子建立了新的 BFC),是一个隔离了的独立容器

  • 如何创建BFC:

    ​ - 浮动元素,float 除 none 以外的值;

    ​ - 绝对定位元素,position(absolute,fixed);

    ​ - display 不为none;

    ​ - overflow 除了 visible 以外的值(hidden,auto,scroll)

  • BFC常见作用

    ​ - BFC清除浮动

    BFC清除浮动.png

    ​ - BFC 会阻止外边距折叠

    BFC阻止外边距塌陷.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 所有题目答案整理自网络,如有错误,接受指正,拒绝批评! 关于html5 HTML5的十大新特性 语义化标签使得页面...
    黄金原野阅读 1,502评论 0 0
  • 1.行内元素和块级元素?img算什么?行内元素怎么转化为块级元素? 行内元素:和有他元素都在一行上,高度、行高及外...
    极乐君阅读 2,505评论 0 20
  • 前端知识点梳理 HTML+CSS部分 1. 怎么将元素水平垂直居中 使用css方法父盒子设置 使用css3的tra...
    不吃鱼的猫_8e95阅读 1,458评论 0 1
  • 关于html静态页面书写的知识点整理 1.web标准:结构,表现,行为 结构(xhtm...
    终相恋阅读 630评论 0 1
  • 有时候压力一大,就会很慌乱。不知道做点什么才能够缓解心中的焦虑。 工作压力 生活压力 所有的这些压力都会让我陷入沉...
    禹坤的修行之路阅读 332评论 0 0