1

我正在尝试使用 div 设置三个部分,中间一个主要部分,左右一个较小的列。我能够做到这一点,但不能让正确的列有一个固定的位置。每当我为此部分添加“位置:固定”时,它都会忽略“浮动:右”并将该部分放在左列的顶部。请注意,我需要在代码中对 div 的左右中间进行排序,否则右列位于其他内容下方的右侧。谢谢。

    <div style = "height: 100%">

    <div style = "width: 15%; float:left; background-image: url(image.jpg);
    background-size: 100% 100%;height: 100%; background-repeat:no-
    repeat; background-position:left top; position: fixed" >
    <div style = "margin-left:20px; margin-right:20px; margin-top:40px; margin-
    bottom:40px">

    <p2>
    content
    </p2>
    </div>
    </div>

    <div style = "width: 15%; float:right; background-image: url(image.jpg);
    background-size: 100% 100%; min-height: 100%; background-repeat:no-
    repeat; **position: fixed;** background-position:right top">
    <div style = "margin-left:20px; margin-right:20px; margin-top:40px; margin-
    bottom:40px">

    <p2>
    content
    </p2>
    </div>
    </div>

    <div style = "width: 60%; margin-left:300px; margin-right:300px; top: 100px" >
    <h1>head  </h1>
    <p>content
    </p>

    </div>
    </div>
4

1 回答 1

1

当你给一个元素固定位置时,你可以强制它在屏幕上的位置。例如,当您的 div 卡在左侧时,您可以添加“left: 100px”以将其向右移动 100px。也就是说,它将元素从左侧移动 100px(向右移动)。您可以将此度量更改为在这种情况下有效的任何值,例如 75%。

还要研究 CSS。将样式直接放入您的标记中可能会变得混乱和重复,我不知道您是否打算让页面随着浏览器窗口缩小,但大多数网页以像素而不是百分比指定列的宽度。

于 2013-02-10T06:53:34.870 回答