如何在css中将div分为多个行和列?

rji*_*rji 3 html css css3 css-float

subdiv里面有div maindiv。我想将sub div分为多个行和列,如下所示。

如何划分subdiv如下

在此处输入图片说明

eir*_*ios 7

你可以做这样的事情

div{
  display:inline-block;
  float:left;
  color:#fff;
  font-size:40px;
}

.one{
  width:150px;
  height:200px;
  background:red;
}

.two{
    width:100px;
  height:200px;
  background:lightgreen;
}

.three{
    width:100px;
  height:200px;
}

.four{
  width:100px;
  height:100px;
background:darkblue;
}
.five{
  width:100px;
  height:100px;
background:blue;
}
Run Code Online (Sandbox Code Playgroud)
<div class="one">1</div>
<div class="two">2</div>
<div class="three">
  <div class="four">4</div>
  <div class="five">5</div>
</div>
Run Code Online (Sandbox Code Playgroud)


Kar*_*eet 5

我知道问题已得到解答,但还有另一种方法可以做到这一点。

您可以使用 css grid 来实现它。阅读有关 css 网格的更多信息

.grid { 
    display: grid;
    grid-template-columns: 10rem 7rem 7rem 7rem;
    grid-template-rows: 7rem 7rem;
    grid-template-areas: 
    "s1 s2 s3"
    "s1 s2 s4"
}
.s1 { 
    grid-area: s1;
    background-color: #FF0000;
}
.s2 { 
    grid-area: s2;
    background-color: #00FF36;
}
.s3 { 
    grid-area: s3;
    background-color: #0030FF;
}
.s4 {
    grid-area: s4;
    background-color: #FF00E4;
}
Run Code Online (Sandbox Code Playgroud)
 <div class="grid">
      <div class="g s1"></div>
      <div class="g s2"></div>
      <div class="g s3"></div>
      <div class="g s4"></div>
 </div>
Run Code Online (Sandbox Code Playgroud)