添加侧边栏时,正文内容移出屏幕

When sidebar added the body content move out of the screen

问题是当我添加宽度为 230px 的侧边栏并将边距添加到主体 230px 时,在这种情况下,而不是主体宽度缩小,内容移出屏幕。这是场景。

<body style="margin-left:230px;">

<aside style="position:absolute;left:0;width:230px;">content here
</aisde>

<header>
</header>

<section>
</section>

<section>
</section>
</body>

在这种情况下,正文内容会收缩,但内容会从正文中移出

您好,首先您的应答器没有关闭,请先尝试更正。 然后使用 margin left 并不是在所有情况下都是最好的解决方案 例如,margin-top:20px 的替代方案;左边距:20px;将是:

<div id="outer">
<div id="inner">
</div>
</div>  
<style>
#outer { position:relative; }
#inner { position:absolute; top:20px; left:20px; }
</style>

为什么要使用绝对位置?使用 position:relative