块布局Box

首先创建容器<div class="box">,内部的块元素支持10%-100%区间的大小配置,每5%为一个间隔,10%、15%、20%依此类推至100%(不含95%),其中支持特殊宽度.grid33、.grid66

类名权重小屏幕 (0-750px)中等屏幕 (0-1200px)大屏幕 (>1200px)
.grid默认保持设定值保持设定值保持设定值
.grid-m高于.grid触发设定值触发设定值不触发
.grid-s高于.grid及.grid-m触发设定值不触发不触发

响应式布局 Box - 图1

  1. <div class="box">
  2. <div class="grid50">.grid50</div>
  3. <div class="grid50">.grid50</div>
  4. <div class="grid33">.grid33</div>
  5. <div class="grid66">.grid66</div>
  6. <div class="grid20">.grid20</div>
  7. <div class="grid80">.grid80</div>
  8. <div class="grid100">.grid100</div>
  9. </div>

没有设定大小值的块元素会自动均分主体空间

响应式布局 Box - 图2

  1. <div class="box">
  2. <div class="grid">.grid</div>
  3. <div class="grid">.grid</div>
  4. </div>
  5. <div class="box">
  6. <div class="grid">.grid</div>
  7. <div class="grid">.grid</div>
  8. <div class="grid40">.grid40</div>
  9. <div class="grid">.grid</div>
  10. <div class="grid">.grid</div>
  11. </div>

响应式布局Responsive Layout

通过预定义的class="grid-m"、class="grid-s"来对中、小屏幕作布局调整例:添加class="grid50 grid-s100",即块元素默认为50%宽度,视窗像素小于750px则转换为100%宽度

  1. <div class="box">
  2. <div class="grid50 grid-s100">.grid50 .grid-s100</div>
  3. <div class="grid50 grid-s100">.grid50 .grid-s100</div>
  4. </div>

class="grid-m"、class="grid-s"可以同时叠加,在不同视窗大小时按权重执行设定值

  1. <div class="box">
  2. <div class="grid50 grid-m75 grid-s100">grid</div>
  3. <div class="grid50 grid-m75 grid-s100">grid</div>
  4. </div>

水平对齐Horizontal Alignment

为容器添加class="x-start"、class="x-center"、class="x-end"定义块元素的水平对齐方式

响应式布局 Box - 图3

  1. <div class="box x-start">
  2. <div class="grid20">.grid20</div>
  3. <div class="grid20">.grid20</div>
  4. </div>
  5. <div class="box x-center">
  6. <div class="grid20">.grid20</div>
  7. <div class="grid20">.grid20</div>
  8. </div>
  9. <div class="box x-end">
  10. <div class="grid20">.grid20</div>
  11. <div class="grid20">.grid20</div>
  12. </div>

为容器添加class="x-between"使块元素两端对齐,块元素之间的间隔都相等

响应式布局 Box - 图4

  1. <div class="box x-between">
  2. <div class="grid20">.grid20</div>
  3. <div class="grid20">.grid20</div>
  4. <div class="grid20">.grid20</div>
  5. </div>

为容器添加class="x-around使块元素两侧的间隔都相等

响应式布局 Box - 图5

  1. <div class="box x-around">
  2. <div class="grid20">.grid20</div>
  3. <div class="grid20">.grid20</div>
  4. <div class="grid20">.grid20</div>
  5. </div>

垂直对齐Horizontal Alignment

为容器添加class="y-start"、class="y-center"、class="y-end"定义块元素的垂直对齐方式

响应式布局 Box - 图6

  1. <div class="box y-start">
  2. <div class="grid">.grid</div>
  3. <div class="grid">.grid</div>
  4. </div>
  5. <div class="box y-center">
  6. <div class="grid">.grid</div>
  7. <div class="grid">.grid</div>
  8. </div>
  9. <div class="box y-end">
  10. <div class="grid">.grid</div>
  11. <div class="grid">.grid</div>
  12. </div>

反序列Reverse

为容器添加class="reverse"使块元素反序列

响应式布局 Box - 图7

  1. <div class="box reverse">
  2. <div class="grid">.grid 1</div>
  3. <div class="grid">.grid 2</div>
  4. <div class="grid">.grid 3</div>
  5. </div>

序列Order

添加class="order1~12"定义块元素的序列

响应式布局 Box - 图8

  1. <div class="box">
  2. <div class="grid order3">.grid .order3</div>
  3. <div class="grid order1">.grid .order1</div>
  4. <div class="grid order2">.grid .order2</div>
  5. </div>

响应式布局 Box - 图9

  1. <div class="box">
  2. <div class="grid order12">.grid .order12</div>
  3. <div class="grid">.grid</div>
  4. <div class="grid order1">.grid .order1</div>
  5. </div>

嵌套Nesting

可以不断向块元素内嵌套更深层容器

响应式布局 Box - 图10

  1. <div class="box">
  2. <div class="grid35">
  3. <div class="box">
  4. <div class="grid50">.grid50</div>
  5. <div class="grid50">.grid50</div>
  6. </div>
  7. </div>
  8. <div class="grid65">
  9. <div class="box">
  10. <div class="grid50">.grid50</div>
  11. <div class="grid50">.grid50</div>
  12. </div>
  13. </div>
  14. </div>

间距Padding

添加class="plr"使块元素填充左右内间距padding-left:0.75rem;padding-right:0.75rem

响应式布局 Box - 图11

  1. <div class="box">
  2. <div class="grid33 plr">.grid33 .plr</div>
  3. </div>