美文网首页
盒子模型简单布局

盒子模型简单布局

作者: Khada | 来源:发表于2018-07-10 08:21 被阅读0次
  • 外边距
    外边距是元素边框与周围元素相距的空间。
    使用margin属性可以设置外边距。
    使用margin-top/right/left/bottom为元素设置四个方向。
    使用margin:0 auto 可以使元素居中。

    .box1{
      width: 200px;
      height: 200px;
      background-color: #bfa;
      border: 10px solid red;
      margin:10px 20px 30px 40px;
     }
    .box2{
      width: 200px;
      height: 200px;
      background-color: yellow;
     }
    
  • display
    通过display来修改元素的性质。
    --block:设置元素为块元素
    --inline:设置元素为行内元素
    --inline-block:设置元素为行内块元素
    --none: 隐藏元素
    visibility
    visibility属性主要用于元素是否可见
    -visible:可见的
    -hidden: 隐藏的
    overflow
    当相关标签里面的内容超出了样式的宽度和高度使,就会发生一些奇怪的事情,浏览器会让内容溢出盒子。
    可以通过overflow来控制内容溢出的情况。
    可选值:
    *--visible:默认值
    --scroll:添加滚动条
    --auto:根据需要添加滚动条
    --hidden:隐藏超出盒子的内容
    文档流
    文档流指的是文档中可实现的对象在排列时所占用的位置,
    将窗体自上而下分为一行行,并在每行中按从左至右的顺序排放元素,即为文档流。
    也就是说在文档流中元素默认会紧贴到上一个元素的右边,如果右边不足以放下元素,元素则会另起一行,在新的一行中继续从左至右摆放。
    这样一来每一个块元素都会另起一行,那么我们如果想在文档流中进行布局就会变得比较麻烦。
    浮动
    所谓浮动指的就是使元素脱离原来的文本流,在父元素中浮动起来。

    --none: 不浮动
    --left:向左浮动
    --right: 向右浮动
    clear: 清除浮动

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>浮动</title>
        <style type="text/css">
        .box1{
            width: 600px;
            height: 200px;
            background-color: red;
            float: left;
        }
        .box2{
          width: 200px;
          height: 200px;
          background-color: yellow;
          float: left;
        }
        .box3{
          width: 200px;
          height: 200px;
          background-color: green;
          float: left;
        }
        </style>
    </head>
    <body>
        <div class="box1"></div>
        <div class="box2"></div>
        <div class="box3"></div>
    </body>
    </html>
    
  • 内联素浮动

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>内联素的浮动</title>
    <style type="text/css">
    .box1{
      background-color: #bfa;
    }
    .s1{
      float: left;
      width: 100px;
      height: 100px;
      background-color: yellow;
    }
    </style>
    </head>
    <body>
    <div class="box1">a</div>
    <span class="s1">hello</span>
    </body>
    </html>
    
  • 简单布局

      <!DOCTYPE html>
      <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>简单布局</title>
    <style type="text/css">
    *{
      margin: 0;
      padding: 0;
    }
    .header{
      width: 1000px;
      height: 150px;
      background-color: yellowgreen;
      margin: 0 auto;
    }
    .content{
      width: 1000px;
      height: 400px;
      background-color: orange;
      margin: 10px auto;
    }
    .left{
      width: 200px;
      height: 100%;
      background-color: skyblue;
      float: left;
    }
    .center{
      width: 580px;
      height: 100%;
      background-color: yellow;
      float: left;
      margin: 0 10px;
    }
    .right{
      width: 200px;
      height: 100%;
      background-color: pink;
      float: left;
    }
    .footer{
      width: 1000px;
      height: 150px;
      background-color: silver;
      margin: 0 auto;
    }
    </style>
    </head>
    <body>
    <div class="header"></div>
    <div class="content">
    <div class="left"></div>
    <div class="center"></div>
    <div class="right"></div>
     </div>
     <div class="footer"></div>
    </body>
    </html>
    
  • 相对定位

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>相对定位</title>
    <style type="text/css">
    .box1{
      height: 200px;
      background-color: red;
      position: relative;
      }
    .box2{
      width: 200px;
      height: 200px;
      background-color: yellow;
      position: relative;
      left: 100px;
      top: 200px;
     }
      .box3{
       width: 200px;
      height: 200px;
      background-color: yellowgreen;
    }
    .s1{
      position: relative;
      width: 200px;
      height: 200px;
      background-color: yellow;
    }
     </style>
    </head>
    <body>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3"></div>
    <span class="s1">我是一个span</span>
    </body>
    </html>
    
  • 绝对定位

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>绝对定位</title>
    <style type="text/css">
      .box1{
      width: 200px;
      height: 200px;
      background-color: red;
      }
      .box2{
      width: 200px;
      height: 200px;
      background-color: yellow;
      position: absolute;
      }
      .box3{
      width: 300px;
      height: 300px;
      background-color: yellowgreen;
      }
      .box4{
      width: 300px;
      height: 300px;
      background-color: orange;
      }
      .s1{
      width: 100px;
      height: 100px;
      background-color: yellow;
      position: absolute;
    }
    </style>
    </head>
    <body>
    <div class="box1"></div>
    <div class="box5">
    <div class="box4">
    <div class="box2"></div>
    </div>
    </div>
    <div class="box3"></div>
    
    <span class="s1">我是一个span</span>
    </body>
    </html>
    
  • 固定定位

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>固定定位</title>
    <style type="text/css">
    .box1{
      width: 200px;
      height: 200px;
      background-color: red;
    }
    .box2{
      width: 200px;
      height: 200px;
      background-color: yellow;
      position: fixed;
      left: 0px;
      top: 0px;
    }
    .box3{
      width: 200px;
      height: 200px;
      background-color: yellowgreen;
    }
    </style>
    </head>
    <body style="height: 5000px;">
    <div class="box1"></div>
    
    <div class="box4" style="width: 300px; height: 300px; background-      color: orange; position: relative;">
    <div class="box2"></div>
        </div>
    
    <div class="box3"></div>
    </body>

相关文章

  • 盒子模型简单布局

    外边距外边距是元素边框与周围元素相距的空间。使用margin属性可以设置外边距。使用margin-top/righ...

  • CSS盒子模型

    CSS盒子模型 1.盒子模型 页面布局要学习三大核心,盒子模型,浮动和定位,学习好盒子模型能非常好的帮助我们布局页...

  • 盒子模型

    1.盒子模型 页面布局要学习三大核心,盒子模型,浮动和定位。学习好盒子模型能非常好的帮助我们布局页面。 网页布局过...

  • 002--css3-flex布局

    一、布局 传统的布局:盒子模型content-box--平时普通的盒子模型(向外扩展)平时普通的盒子,添加padd...

  • 十六、盒子模型

    一、盒子模型 页面布局要学习三大核心,盒子模型,浮动和定位。学习好盒子模型能非常好的帮助我们布局页面。、 1.1 ...

  • box-sizing属性使用场景

    关键词:布局 盒子模型盒子模型盒子模型在前端开发中有着非常重要的地位。盒子模型的组成由content+paddin...

  • css源码笔记(四)【爱创课堂专业前端培训】

    复习: 1.1布局模型——前端培训机构 与盒子模型一样是最基础、最核心的东西,但是布局模型是从盒子模型基础上进行布...

  • 弹性盒子--Flexbox布局!!

    弹性盒子布局模型 1. Flex布局是什么? Flex是发了flexbox 的缩写,意为“弹性布局”,用来为盒子状...

  • 12 CSS中的盒子模型

    页面布局要学习三大核心,盒子模型、浮动和定位。学好盒子模型能非常好的帮助我们布局。网页布局.png 1.看透网页布...

  • CSS盒模型

    盒子模型是CSS中一个重要的概念,理解了盒子模型才能更好的排版和布局。盒子模型有两种,分别是 IE 盒子模型和标准...

网友评论

      本文标题:盒子模型简单布局

      本文链接:https://www.haomeiwen.com/subject/zsnxpftx.html