我设置了一个页面,以便将我的两个<div>块(分别称为leftCol和rightCol)设置为填充页面宽度的25%和75%。这很好,但是当浏览器窗口变大或缩小时,我需要调整它的大小,这样我的文本就不会渗入左侧的图片列中。
下面的当前CSS
.leftCol {
width: 25%;
height: 100%;
float: left;
}
.rightCol {
width: 75%;
height: 100%;
float: left;
}我尝试过使用width: auto,但它没有像我希望的那样以全屏宽度显示两列,在文本上方显示一行图像,而不是像我希望的那样在文本的左侧显示一列图片。任何帮助都是非常感谢的。
发布于 2020-10-09 08:12:49
在容器上使用flex,并将leftColumn和rightColumn都包装在容器内。
您可以观察到,当您调整浏览器窗口的大小时,列中的文本将换行到下一行。
假设这是你需要的,因为你没有发布你的源代码。
.container {
display: flex;
flex-direction: row;
width: 100%;
}
.leftColumn {
width: 25%;
border: 1px solid red;
}
.rightColumn {
width: 75%;
border: 1px solid blue;
}<div class="container">
<div class="leftColumn">
Left column content Left column content Left column content Left column content Left column content
</div>
<div class="rightColumn">
Right column content Right column content Right column content Right column content Right column content Right column content Right column content Right column content Right column content Right column content Right column content Right column content
Right column content
</div>
</div>
发布于 2020-10-09 08:10:32
发布于 2020-10-09 08:11:16
您可以尝试使用flexbox或CSS Grid Layout以更现代的方式设置布局。并在窗口大小改变时使用一些媒体查询断点。我看不出你的整个网站是如何用html和css构建的,但试着玩一下这个吧。在html中添加一个div,其中包含一个名为container的类,它同时包装左右两列,然后在CSS文件中添加:
.container {
display:grid;
width: 100%;
height: 100vh;
grid-template-columns: 1fr 1fr 1fr;
grid-template-areas:
"columns columns columns";
}
.leftCol {
display:grid;
grid-area:columns;
justify-content:start;
width: 25%;
height: 100%;
}
.rightCol {
display:grid;
grid-area:columns;
justify-content:end;
width: 75%;
height: 100%;
}https://stackoverflow.com/questions/64272190
复制相似问题