【发布时间】:2020-10-22 22:22:43
【问题描述】:
我正在制作一个具有响应式布局的页面。我无法将 2 个 DIV 放在一个 DIV 元素下。我从这里尝试了 Flexbox、Float 和其他解决方案。
col-1,col-2 和 col-3 都在 .three-col div 中
这是 CSS:
.three-col {
margin: 20px auto 0 auto;
flex-direction: row;
}
@media screen and (min-width: 550px) {
body {
background-color: yellow;
}
!!!HERE IS THE PROBLEM!!!
.col-2
{
float: left;
}
.col-3
{
float:left;
clear: left;
}
}
@media screen and (min-width: 600px) {
.three-col {
margin: 20px auto 0 auto;
display: flex;
}
}
.col-1, .col-2, .col-3 {
padding: 20px;
}
.col-1 {
background-color: lightpink;
}
.col-2 {
background-color: lightgreen;
}
.col-3 {
background-color: aquamarine;
}
这就是它在 CSS 文件的中间情况下的样子:
HTML 模型:
<body>
<div class="three-col">
<div class="col-1">
<h1>Column One</h1>
<p>
Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a
.</p>
<p>
Lorem Ipsum
from a line in section 1.10.32.
</p>
</div>
<div class="col-2">
<h2>Column Two</h2>
<p>There ng this the first true generator on the Internet. It uses a dictionary of over 200
Latr, or
non-characteristic words etc.</p>
</div>
<div class="col-3">
<h2>Column Three</h2>
<p>Iibution
of letters, as opposed to using 'Content here, content here', making it look like reglish.</p>
<p>Many desktop publishing packages and web page editors now use Lorem Ipsum as their .</p>
</div>
</div>
</body>
【问题讨论】:
-
请同时发布您的 HTML。我们需要一个minimal reproducible example