无法正确浮动 div
Not able to float div correctly
我有一个列表,其中包含 3 个块,每个块通常占 33%。当我将 window 调整到更小的尺寸时,我希望前两个块一个叠一个叠起来,占据宽度的 50%,而第三个元素跨越并占据另外 50% 的整体,但我我只能跨越第一行的前两个块和第二行的第三个块。
并且在进一步最小化它时,我希望所有这些都一个接一个地堆叠。
我添加了布局:
这是我的代码:
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 和 媒体查询
来做到这一点
.div-1, .div-2, .div-3 {
border: 1px solid black;
}
.content {
display: flex;
flex-direction: row;
min-height: 100vh;
}
.group {
flex: 2;
display: flex;
}
.div-3, .div-1, .div-2 {
flex: 1;
}
@media(max-width: 992px) {
.group {
flex-direction: column;
}
}
@media(max-width: 480px) {
.content {
flex-direction: column;
}
}
<div class="content">
<div class="group">
<div class="div-1">Div 1</div>
<div class="div-2">Div 2</div>
</div>
<div class="div-3">Div 3</div>
</div>
左右拖动输出来模拟媒体查询。请记住,我没有遵守您的媒体查询,只是使用我自己的来模拟示例。
<li class="listChild">
<div class="time">
<div class="some-container">
<div class="listItem datum">
list one
</div>
<div class="listItem zeit">
list two
</div>
</div>
<div class="listItem type">
list three
</div>
</div>
</li>
* {
box-sizing: border-box;
}
.listItem {
border: 1px solid #000;
padding: 10px;
float: left;
width: 250px;
height: 30px;
}
.some-container {
float: left;
}
.some-container + .listItem {
float: left;
}
@media (max-width: 800px) and (min-width: 300px) {
.some-container .listItem {
height: 30px;
float: none;
}
.some-container + .listItem {
height: 60px;
}
}
@media (max-width: 299px) {
.listItem {
float: none;
width: 100%;
}
}
您不一定需要使用 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>
我有一个列表,其中包含 3 个块,每个块通常占 33%。当我将 window 调整到更小的尺寸时,我希望前两个块一个叠一个叠起来,占据宽度的 50%,而第三个元素跨越并占据另外 50% 的整体,但我我只能跨越第一行的前两个块和第二行的第三个块。
并且在进一步最小化它时,我希望所有这些都一个接一个地堆叠。
我添加了布局:
这是我的代码:
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 和 媒体查询
来做到这一点.div-1, .div-2, .div-3 {
border: 1px solid black;
}
.content {
display: flex;
flex-direction: row;
min-height: 100vh;
}
.group {
flex: 2;
display: flex;
}
.div-3, .div-1, .div-2 {
flex: 1;
}
@media(max-width: 992px) {
.group {
flex-direction: column;
}
}
@media(max-width: 480px) {
.content {
flex-direction: column;
}
}
<div class="content">
<div class="group">
<div class="div-1">Div 1</div>
<div class="div-2">Div 2</div>
</div>
<div class="div-3">Div 3</div>
</div>
左右拖动输出来模拟媒体查询。请记住,我没有遵守您的媒体查询,只是使用我自己的来模拟示例。
<li class="listChild">
<div class="time">
<div class="some-container">
<div class="listItem datum">
list one
</div>
<div class="listItem zeit">
list two
</div>
</div>
<div class="listItem type">
list three
</div>
</div>
</li>
* {
box-sizing: border-box;
}
.listItem {
border: 1px solid #000;
padding: 10px;
float: left;
width: 250px;
height: 30px;
}
.some-container {
float: left;
}
.some-container + .listItem {
float: left;
}
@media (max-width: 800px) and (min-width: 300px) {
.some-container .listItem {
height: 30px;
float: none;
}
.some-container + .listItem {
height: 60px;
}
}
@media (max-width: 299px) {
.listItem {
float: none;
width: 100%;
}
}
您不一定需要使用 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>