html - 无法正确 float div

标签 html css

我有一个包含 3 个 block 的列表,每个 block 通常占 33%。当我将窗口调整为更小的尺寸时,我希望前两个 block 一个一个地堆叠起来并占据宽度的 50%,而第三个元素跨越并占据另外 50% 的整体但我只能跨越第一行的前两个 block 和第二行的第三个 block 。

在进一步最小化它时,我希望所有这些都一个接一个地堆叠。

我已经添加了布局: enter image description here

这是我的代码:

li.listChild .time-home {
  float: left;
  height: auto;
  width: 100%;
  line-height: 21px;
  font-size: 12px;
  font-weight: 700;
  text-align: right; 
}
@media only screen and (min-width: 800px) and (max-width: 1023px) {
  li.listChild .time-home {
    width: 100%; } 
}
li.listChild .time-home .listItem {
  float: left; }
li.listChild .time-home .listItem.datum-home {
  width: 33%;
  font-weight: 700; }
@media only screen and (min-width: 1024px) and (max-width: 1443px) {
  li.listChild .time-home .listItem.datum-home {
    width: 50%;
    border-bottom: 1px #e8e8e8 solid; }
}
@media only screen and (min-width: 800px) and (max-width: 1023px) {
  li.listChild .time-home .listItem.datum-home {
    width: 100%;
    border-bottom: 1px #e8e8e8 solid; } 
}
li.listChild .time-home .listItem.zeit-home {
  font-weight: 400;
  width: 33%; 
}
@media only screen and (min-width: 1024px) and (max-width: 1443px) {
  li.listChild .time-home .listItem.zeit-home {
    width: 50%;
    border-bottom: 1px #e8e8e8 solid; }
}
@media only screen and (min-width: 800px) and (max-width: 1023px) {
  li.listChild .time-home .listItem.zeit-home {
    width: 100%;
    border-bottom: 1px #e8e8e8 solid; }
}
li.listChild .time-home .listItem.type-home {
  width: 33%;
  color: #0293ed;
  border: none;
  font-weight: 700;
}
@media only screen and (min-width: 1024px) and (max-width: 1443px) {
  li.listChild .time-home .listItem.type-home {
    width: 100%;
    border-bottom: 1px #e8e8e8 solid;
    border-right: 1px #e8e8e8 solid; }
}
@media only screen and (min-width: 800px) and (max-width: 1023px) {
  li.listChild .time-home .listItem.type-home {
    width: 100%;
    border-bottom: 1px #e8e8e8 solid;
    border-right: 1px #e8e8e8 solid; } 
}
<li class="listChild">
    <div class="time">
        <div class="listItem datum">
            3.6.93
        </div>
        <div class="listItem zeit">
            4.6.93
        </div>
        <div  class="listItem type">
        Thomas
    </div>
    </div>
    
</li>

最佳答案

您不一定需要使用 flexbox,您可以使用绝对定位。

示例:https://jsfiddle.net/yyuwmv1r/

* {
  box-sizing: border-box;
}

.container {
  height: 300px;
  width: 100%;
  position: relative;
}

.one,
.two,
.three {
  border: 2px solid black;
  height: 33.33%;
  width: 100%;
  float: left;
  background: red;
}
.two {
  background: blue;
}
.three {
  background: green;
}

@media only screen and (min-width: 800px) and (max-width: 1200px) {
  .one,
  .two,
  .three {
    position: absolute;
  }
  .one {
    top: 0;
    left: 0;
    height: 50%;
    width: 50%;
  }
  .two {
    top: 50%;
    left: 0;
    height: 50%;
    width: 50%;
  }
  .three {
    top: 0;
    left: 50%;
    height: 100%;
    width: 50%;
  }
}

@media only screen and (min-width: 1200px) {
  .one,
  .two,
  .three {
    border: 2px solid black;
    height: 100%;
    width: 33.33%;
    float: left;
    background: red;
  }
  .two {
    background: blue;
  }
  .three {
    background: green;
  }
}
<div class="container">
  <div class="one">
    One
  </div>
  <div class="two">
    Two
  </div>
  <div class="three">
    Three
  </div>
</div>

关于html - 无法正确 float div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34315087/

相关文章:

javascript - 过滤投资组合时在转型中的流沙跳跃

html - 超链接 <a> 悬停时不改变颜色

html - IE7 Bug 流向右

javascript - 将元素推到父级的底部

javascript:将 <svg> 元素保存到磁盘上的文件

html - 在 anchor 内添加了无法解释的空间

javascript - 突出显示 html 表格中具有选定值的行

css - 标题固定,可滚动的特立尼达表

javascript - 使用 javascript 获取特定列表框选定的值

html - 如何删除 span 标签之间的空格,同时在每个 span 标签中保留空格?