美文网首页
盒子模型和边框

盒子模型和边框

作者: 骚X | 来源:发表于2018-11-21 11:12 被阅读0次

盒子模型(框模型)

一个盒子分为四部分
1.内容区(content)
2.内边距(padding)
3.边框(border)
4.外边距(margin)
盒子的大小是由(内容区、内容距、边框)决定
.box{
    width:100px;
    height:100px;
    background-color:#bfa;
    border-width:10px;
    border-color:red;
    border-style:solid;
    }
设置边框上下左右的宽度
.box{
    boder-top-width:10px;
}
上top、下bottom、左left、右right
设置边框上下左右的颜色
.box{
    border-top-color;
  }
设置边框的形状
.box{
      border-style:dotted;
    }
dotted(点状)、dashed(虚线)、double(双线)、solid(实线)

边框

.box{
      width:100px;
      height:100px;
      background-color:#bfa;
      border-width:1px;
      border-color:red;
      border-style:solid;
      }
如果不设置边框的宽度和颜色浏览器会默认认为黑色3px;
自定义边框颜色
.box{
      width:100px;
      height:100px;
      background-color:#bfa;
      border-top:10px  solid red;
      }
上top、下bottom、左left、右right
边框的简写
.box{
      width:100px;
      height:100px;
      background-color:#bfa;
      border:10px  solid red;
      }
上下都被设置就右面不会设置边框样式
.box{
      width:100px;
      height:100px;
      background-color:#bfa;
      border:10px  red   solid;
      border-right:none;
      }

内边距

.box{
        width:100px;
        height:100px;
        background-color:#bbffaa;
        border:red  10px   solid;
        padding-bottom:20px;
        padding-left:20px;
        padding-right:20px;
      }
.box1{
          width:100%;
          height:100%;
          background-color:orange;
      }

外边距

 .box{ 
          width: 100px;
          height: 100px; 
          background-color: #bbffaa; 
          border:red 10px solid; 
          margin-top: 20px; 
          margin-bottom:20px; 
          margin-left:20px; 
          margin-right:20px; 
      } 

.box1{ 
          width: 100px; 
          height: 100px; 
          background-color: orange; 
      }

margin外边距

.box{
        width:100px;
        height:100px;
        backgound-color:##bbffaa;
        border:red 10px  solid;
        margin-top: -50px;
        margin-bottom:-50x;
        margin-left:-50px;
        margin-right:-50px;
    }
.box1{
        width:100px;
        height: 100px;
        nackground-color:orange;
      }

给margin设置auto

.box{
      width:100px;
       height:100px;
        background-color:#bbffaa;
       border:red  10px  solid;
        margin-left:auto;
        margin-right:auto;
        margin: 0 auto;
    }

.box1{
      width:100px;
      height:100px;
      backround-color:orange;
      }
  注:如果设定左外边距或者有外边距的话会把外边距设为最大,垂直方向设置auto相当于0,左右同时设置auto,就会居中.

相关文章

  • CSS 盒子模型

    CSS盒子模型 盒子模型边框 CSS盒子模型的宽度和高度 CSS模型的填充 CSS盒子模型的边界 填充和边界的区别

  • 2019-05-29

    盒子模型也叫框模型: 盒子的大小由 内容区和内边距和边框来决定的。 盒子的大小=内容区+内边距+边框的宽度 内容区...

  • 盒子模型.md

    盒子模型有两种IE盒子模型和标准盒子模型。盒子由内容,内边距,外边距,边框和外边距组成。 在标准盒子模型下,整个盒...

  • 盒子模型、CSS边距合并、inline-block缝隙、BFC

    1 盒子模型的组成 盒子模型是由边距、边框、填充和内容组成的。其中边距、边框、填充可以在盒子模型上下左右四个方向上...

  • 盒模型,边框,内外边距,浏览器的默认样式,内联元素的盒模型,di

    盒子模型:一个盒子分为内容区content 内边距padding 边框border和外边距margin 盒子大小=...

  • 3.CSS盒子模型 border、margin、padding

    盒子模型有两种,分别是 ie 盒子模型和标准 w3c 盒子模型 border 边框 如下代码代表20像素蓝色的实线...

  • 盒子模型和边框

    盒子模型(框模型) 一个盒子分为四部分1.内容区(content)2.内边距(padding)3.边框(borde...

  • 盒子模型和边框

    盒子模型(框模型) 一个盒子分为四部分 1.内容区(content) 2.内边距(padding) 3.边框(bo...

  • CSS之盒子模型

    CSS 盒子模型描述 盒子模型的属性有边框、内边距、外边距,如图所示: 边框:使用border属性来定义,元素的边...

  • css基础系列

    盒子模型 盒子模型的概念 高和宽的设置 边框的设置 内边距的设置 外边距的设置 盒子的计算 元素显示的方式 盒子模...

网友评论

      本文标题:盒子模型和边框

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