html - 使用 float 的 CSS tile 布局

标签 html css layout css-float

我有 7 个图 block ,我想使用 CSS 和 float 布局,如下图所示 enter image description here

但是我无法让最后 2 个图 block 正确“ float ”。 代码笔链接:http://codepen.io/anon/pen/EPeRqO?editors=1100

这是我的代码

<div class="container">
  <div class="first">first</div>
  <div class="sixth">6th</div>
  <div class="fourth">fourth</div>
  <div class="second">second</div>
  <div class="seventh">seventh</div>
  <div class="fifth">fifth</div>
  <div class="third">third</div>
</div>

还有我的 CSS

.container {max-width:1220px; max-height:370px;}
div{margin-right:10px;}
.first{  float:left;  width:550px;  height:370px;  background-color:#d7df52;  }
.second{  float:left;  width:210px;  height:190px;  background-color:#51a279;  }
.third{  float:left;  width:210px;  height:215px;  background-color:#d17466;  }
.fourth{  float:right;  width:210px;  height:190px;  background-color:#d17466;  }
.fifth{  float:right;  width:210px;  height:180px;  background-color:#d17466;  }
.sixth{  float:right;  width:210px;  height:170px;  background-color:#d17466;  }
.seventh{  float:right;  width:210px;  height:200px;  background-color:#d17466;  }

最佳答案

Flebox 可以做到这一点......也可以按顺序:

Codepen Demo

相关部分

.container {
  display: flex;
  justify-content: flex-start;
  flex-direction: column;
  flex-wrap:wrap;
  }

* {
  box-sizing: border-box;
}

.container {
  width: 1230px;
  display: flex;
  justify-content: flex-start;
  flex-direction: column;
  flex-wrap:wrap;
  height: 430px;
  padding-left: 10px;
  }

.container div {
  margin: 10px 10px 0 0;
}


.first {
  margin-left: 10px;
  width: 550px;
  height: 370px;
  background-color: #d7df52;
}

.second {
   width: 210px;
  height: 190px;
  background-color: #51a279;
}

.third {
  width: 210px;
  height: 215px;
  background-color: #d17466;
}

.fourth {
  width: 210px;
  height: 190px;
  background-color: #d17466;
}

.fifth {
  width: 210px;
  height: 180px;
  background-color: #d17466;
}

.sixth {
  width: 210px;
  height: 170px;
  background-color: #d17466;
}

.seventh {
  width: 210px;
  height: 200px;
  background-color: #d17466;
}
<div class="container">
  <div class="first">first</div>
  <div class="second">second</div>
  <div class="third">third</div>
  <div class="fourth">fourth</div>
  <div class="fifth">fifth</div>
  <div class="sixth">sixth</div>  
  <div class="seventh">seventh</div>  
</div>

关于html - 使用 float 的 CSS tile 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35204827/

相关文章:

Android 在 setContentView 之后应用设置

html - 无法将图像放在页面顶部

html - 全屏背景不适用于移动设备

jquery对齐页面的容器表

javascript - Bootstrap 默认导航栏无法正常工作

html - chrome 单选按钮上的白色背景

rigraph 绘图布局错误 : incorrect number of subscripts on matrix

html - 我的 anchor 不工作

Firefox 中的 CSS Sprite 兼容性

java - 为智能手机的具体模型选择布局参数