美文网首页
手写栅格系统

手写栅格系统

作者: 我是Msorry | 来源:发表于2021-01-22 15:20 被阅读0次

原理是浮动+百分比+媒体查询,或者flex+百分比+媒体查询。把页面水平分成12格或者24格,通过约定的 class 来控制元素占几个格子。

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>JS Bin</title>
    <style>
      

* {
  box-sizing: border-box;
}

.container {
  background: yellow;
  padding-left: 10px;
  padding-right: 10px;
  margin-right: auto;
  margin-left: auto;
}


.container::after{
  content: '';
  display: block;
  clear: both;
}

.row {
  margin-left: -10px;
  margin-right: -10px;
}

@media (min-width: 768px) {
  .container {
    width: 750px;
  }
}
@media (min-width: 992px) {
  .container {
    width: 970px;
  }
}
@media (min-width: 1200px) {
  .container {
    width: 1170px;
  }
}






.col-xs-1, .col-xs-2, .col-xs-3, .col-xs-4, .col-xs-5, .col-xs-6, .col-xs-7, .col-xs-8, .col-xs-9, .col-xs-10, .col-xs-11, .col-xs-12 {
  float: left;
}

.col-xs-12 {
  width: 100%;
}
.col-xs-11 {
  width: 91.66666667%;
}
.col-xs-10 {
  width: 83.33333333%;
}
.col-xs-9 {
  width: 75%;
}
.col-xs-8 {
  width: 66.66666667%;
}
.col-xs-7 {
  width: 58.33333333%;
}
.col-xs-6 {
  width: 50%;
}
.col-xs-5 {
  width: 41.66666667%;
}
.col-xs-4 {
  width: 33.33333333%;
}
.col-xs-3 {
  width: 25%;
}
.col-xs-2 {
  width: 16.66666667%;
}
.col-xs-1 {
  width: 8.33333333%;
}



@media (min-width: 768px) {
  .col-sm-1, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11, .col-sm-12 {
    float: left;
  }
  .col-sm-12 {
    width: 100%;
  }
  .col-sm-11 {
    width: 91.66666667%;
  }
  .col-sm-10 {
    width: 83.33333333%;
  }
  .col-sm-9 {
    width: 75%;
  }
  .col-sm-8 {
    width: 66.66666667%;
  }
  .col-sm-7 {
    width: 58.33333333%;
  }
  .col-sm-6 {
    width: 50%;
  }
  .col-sm-5 {
    width: 41.66666667%;
  }
  .col-sm-4 {
    width: 33.33333333%;
  }
  .col-sm-3 {
    width: 25%;
  }
  .col-sm-2 {
    width: 16.66666667%;
  }
  .col-sm-1 {
    width: 8.33333333%;
  }

}
@media (min-width: 992px) {
  .col-md-1, .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8, .col-md-9, .col-md-10, .col-md-11, .col-md-12 {
    float: left;
  }
  .col-md-12 {
    width: 100%;
  }
  .col-md-11 {
    width: 91.66666667%;
  }
  .col-md-10 {
    width: 83.33333333%;
  }
  .col-md-9 {
    width: 75%;
  }
  .col-md-8 {
    width: 66.66666667%;
  }
  .col-md-7 {
    width: 58.33333333%;
  }
  .col-md-6 {
    width: 50%;
  }
  .col-md-5 {
    width: 41.66666667%;
  }
  .col-md-4 {
    width: 33.33333333%;
  }
  .col-md-3 {
    width: 25%;
  }
  .col-md-2 {
    width: 16.66666667%;
  }
  .col-md-1 {
    width: 8.33333333%;
  }

}
@media (min-width: 1200px) {
  .col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8, .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12 {
    float: left;
  }
  .col-lg-12 {
    width: 100%;
  }
  .col-lg-11 {
    width: 91.66666667%;
  }
  .col-lg-10 {
    width: 83.33333333%;
  }
  .col-lg-9 {
    width: 75%;
  }
  .col-lg-8 {
    width: 66.66666667%;
  }
  .col-lg-7 {
    width: 58.33333333%;
  }
  .col-lg-6 {
    width: 50%;
  }
  .col-lg-5 {
    width: 41.66666667%;
  }
  .col-lg-4 {
    width: 33.33333333%;
  }
  .col-lg-3 {
    width: 25%;
  }
  .col-lg-2 {
    width: 16.66666667%;
  }
  .col-lg-1 {
    width: 8.33333333%;
  }

}



.row > * {
  border: 1px solid;
  text-align: center;
}

.aside {
  min-height: 200px;
  background: pink;
}

.main {
  min-height: 300px;
  background: grey;
}
}
    </style>
  </head>
  <body>

    <div class="container">
      <h1>hello</h1>
    </div>
    <div class="container">
      <div class="row">
        <div class="col-xs-12 col-lg-6">1</div>
        <div class="col-xs-12 col-sm-3">2</div>
        <div class="col-xs-12 col-sm-3">3</div>
        <div class="col-xs-12 col-sm-3">4</div>    
      </div>
    </div>
    <div class="container">
      <div class="row">
        <div class="aside col-md-3">aside</div>
        <div class="main col-md-9">main</div>
      </div>
    </div>
  </body>
</html>
image.png

相关文章

  • 手写栅格系统

    原理是浮动+百分比+媒体查询,或者flex+百分比+媒体查询。把页面水平分成12格或者24格,通过约定的 clas...

  • 栅格化系统在设计中的运用

    刚开始对栅格系统有很多疑惑,什么是栅格化系统?Bootstrap中为什么要使用栅格系统?设计师为什么要学习栅格系统...

  • 什么是栅格系统

    一、概念 1、栅格系统(grid systems),也叫“网格系统”。栅格设计系统(又称网格设计系统、标准尺寸系统...

  • UI设计新手福利!独家揭秘IOS系统图标栅格系统

    今天我们来详细讲解下如何通过IOS应用图标栅格推导出系统图标的栅格系统。首先我们需要了解下应用图标栅格系统的比例关...

  • bootstrap栅格系统分析

    bootstrap栅格系统 bootstrap栅格系统是bootstrap的核心以及精髓所在 一、容器 1.流体容...

  • 四、bootstrap栅格系统、表单

    知识点: 1、栅格系统2、表单 1、栅格系统 1)响应式网格系统随着屏幕或视口(viewport)尺寸的增加,系统...

  • Bootstrap响应式栅格布局实现方法

    栅格系统的原理 Bootstrap的栅格系统下面我们将一起来看一下常见的栅格布局的设计和bootstrap中的设计...

  • 栅格系统

    栅格系统(grid systems)也称网格系统,指的是一种运用固定的格子设计版面布局方法。 使用栅格系统进行网页...

  • 栅格系统

    简介 栅格系统用于通过一系列row与列colum的组合来创建页面布局,HTML内容就放于这些创建好的布局中。 行(...

  • 栅格系统

    JS文件 bootstrap.min.js application.js highlight.min.js hol...

网友评论

      本文标题:手写栅格系统

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