网格上的CSS DIV布局

时间:2017-01-27 09:47:27

标签: html css html5

enter image description here

是否可以使用div的

获取此布局

4 个答案:

答案 0 :(得分:7)

您可以在margin-top上使用浮点数和否定.e执行此操作。使用砖石,您不需要margin-top this

* {
  box-sizing: border-box;
}
.content {
  width: 200px;
  height: 200px;
  border: 1px solid black;
}
.item {
  border: 1px solid black;
  float: left;
  display: flex;
  align-items: center;
  justify-content: center;
}
.a,
.d {
  width: 33.3333333%;
  height: 66.67%;
}
.b,
.e {
  width: 66.67%;
  height: 33.3333333%;
}
.e {
  margin-top: -33.3333333%;
}
.c {
  width: 33.3333333%;
  height: 33.3333333%;
}
<div class="content">
  <div class="a item">a</div>
  <div class="b item">b</div>
  <div class="c item">c</div>
  <div class="d item">d</div>
  <div class="e item">e</div>
</div>

答案 1 :(得分:2)

是的,这是可能的。

我为你制作了一个快速片段。使用position: absolute

* {
  padding: 0;
  margin: 0;
}

.container {
  width: 150px;
  height: 150px;
}

.a {
  position: absolute;
  height: 100px;
  width: 50px;
  background-color: #CCC;
}

.b {
  position: absolute;
  left: 50px;
  height: 50px;
  width: 100px;
  background-color: #C2C2C2;
}

.c {
  position: absolute;
  left: 50px;
  top: 50px;
  width: 50px;
  height: 50px;
  background-color: #EEE;
}

.d {
  position: absolute;
  left: 100px;
  top: 50px;
  height: 100px;
  width: 50px;
  background-color: #F0F0F0;
}

.e {
  position: absolute;
  left: 0px;
  top: 100px;
  width: 100px;
  height: 50px;
  background-color: #DDD;
}
<div class="container">

  <div class="a"></div>
  <div class="b"></div>
  <div class="c"></div>
  <div class="d"></div>
  <div class="e"></div>

</div>

答案 2 :(得分:2)

使用表

尝试此代码

&#13;
&#13;
table {
    border-collapse: collapse;
   border: 1px solid black;
}

table, td, th {
    border: 1px solid black;

}

td
{
    padding:10px;
  }
&#13;
<table  >
  <tr>
    <td rowspan="2">A</td>
    <td colspan="2">B</td>
    </tr>
  
    <tr>
    <td>C</td>
    <td rowspan="2">D</td>
    </tr>
  
    <tr>
    <td colspan="2">E</td>
    </tr>
  </table>
&#13;
&#13;
&#13;

答案 3 :(得分:1)

试试这段代码

workspace.xml

CSS代码

workspace.xml

此处代码的上传代码https://jsfiddle.net/romesh60/odo4r5aq/2/

相关问题