【发布时间】:2022-02-11 13:14:21
【问题描述】:
我是 CSS 新手。 试图研究一些布局并遇到这个问题。 在 HTML 中。我有
<div id="wrapper">
<aside id="sidebar" class="left">
</aside>
<div class="content">
Lorem ipsum blah blah (cutted: about 100lines)
</div>
<aside id="sidebar" class="right">
</aside>
</div>
我试图阻止左右侧边栏(旁边)滚动。无论我滚动多少主目录,它都会一直呆在那里;我已将其位置设置为固定,看起来一切都很好。问题是,调整大小时,主要内容与右侧边栏(旁边)重叠。我已经尝试过 position: relative 和 absolute 向右并将其更改为 div 但没有任何反应。 目标是 - 当我的 chrome 浏览器缩小时,它应该显示水平/垂直滚动条,而主要内容没有任何重叠。无论我的主要内容有多长,侧边栏都应该一直存在!先感谢您! 下面的CSS
body, html {
font-family: Helvetica;
background-color: rgba(0, 0, 0);
}
#sidebar {
position: fixed;
width: 400px;
height: 100%;
margin-top: 120px;
top: 0;
}
.left {
left: 0;
bottom: 0;
background-color: rgb(82, 50, 50);
}
.content {
display: inline-block;
background-color: rgb(255, 255, 255);
margin-top: 120px;
top: 0;
width: 800px;
height:100%;
margin-left: 400px;
margin-right: 400px;
}
.right {
right: 0;
bottom: 0;
background-color: rgb(255, 217, 0);
}
#wrapper {
margin-left:0;
margin-right:0;
max-width: 1600px;
border:1px solid white;
}
【问题讨论】:
-
使用 flex,您可以通过更现代和可扩展的方法获得完全相同的结果