将横幅放置在顶部作为顶层

发布于 2024-12-29 08:02:05 字数 2083 浏览 0 评论 0原文

这是该页面的链接: http://whiterootmedia.com/test/test3

这是代码:

    <div id="banner" style="position:absolute; top:0px; width:100%; background:url('../../images/banner_repeat.jpg'); background-repeat:repeat-x; <!-- border:solid pink 1px; -->"> 
    <ul id="banner_ul">
    <li id="wrm"><a href="http://whiterootmedia.com"><i>The homepage of White Root Media!</i></a></li>
    <li id="google"><a href="https://plus.google.com/u/0/b/115943543157099352927/115943543157099352927" target="_blank"><i>+1 us on Google!</i></a></li>
    <li id="facebook"><a href="http://www.facebook.com/pages/White-Root-Media/194381903928501" target="_blank"><i>Like us on Facebook!</i></a></li>
    <li id="twitter"><a href="http://twitter.com/#!/WhiteRootMedia" target="_blank"><i>Tweet about us on Twitter!</i></a></li>
    </ul>

    <div id="container" style="<!-- border:solid yellow 1px -->; display: table;">

    <div id="content" style="<!-- border:solid purple 1px; --> display:table-cell; ">
    This content determines the height. The text will not wrap. There will be a min-width yet to be determined.
    This content determines the height. The text will not wrap. There will be a min-width yet to be determined.
    This content determines the height. The text will not wrap. There will be a min-width yet to be determined.

    </div>

    <div id="right_column" style="display: table-cell; <!-- border:solid orange 1px; --> height:100%; width:270px; background-image:url('../../images/treetrunk7.png');background-repeat:repeat-y;">tree</div>

    </div>

    <div id="footer" style="position:relative; top:-1px; background-image:url('../../images/grass.png'); background-repeat:repeat-x; width:100%; height:100px;">grass</div>

我希望横幅位于顶层,而“容器”div 位于下面

here's the link to the page:
http://whiterootmedia.com/test/test3

here's the code:

    <div id="banner" style="position:absolute; top:0px; width:100%; background:url('../../images/banner_repeat.jpg'); background-repeat:repeat-x; <!-- border:solid pink 1px; -->"> 
    <ul id="banner_ul">
    <li id="wrm"><a href="http://whiterootmedia.com"><i>The homepage of White Root Media!</i></a></li>
    <li id="google"><a href="https://plus.google.com/u/0/b/115943543157099352927/115943543157099352927" target="_blank"><i>+1 us on Google!</i></a></li>
    <li id="facebook"><a href="http://www.facebook.com/pages/White-Root-Media/194381903928501" target="_blank"><i>Like us on Facebook!</i></a></li>
    <li id="twitter"><a href="http://twitter.com/#!/WhiteRootMedia" target="_blank"><i>Tweet about us on Twitter!</i></a></li>
    </ul>

    <div id="container" style="<!-- border:solid yellow 1px -->; display: table;">

    <div id="content" style="<!-- border:solid purple 1px; --> display:table-cell; ">
    This content determines the height. The text will not wrap. There will be a min-width yet to be determined.
    This content determines the height. The text will not wrap. There will be a min-width yet to be determined.
    This content determines the height. The text will not wrap. There will be a min-width yet to be determined.

    </div>

    <div id="right_column" style="display: table-cell; <!-- border:solid orange 1px; --> height:100%; width:270px; background-image:url('../../images/treetrunk7.png');background-repeat:repeat-y;">tree</div>

    </div>

    <div id="footer" style="position:relative; top:-1px; background-image:url('../../images/grass.png'); background-repeat:repeat-x; width:100%; height:100px;">grass</div>

I would like the banner to sit at the top layer while the "container" div to sit underneath

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

想挽留 2025-01-05 08:02:05

这是一个演示: http://jsfiddle.net/Wyvk8/

我删除了您的内联 CSS 样式并应用了它们通过 CSS 规则如下:

html, body {
    height     : 100%;
    min-height : 100%;
}
#banner {
    position      : absolute;
    top           : 0;
    left          : 0;
    height        : 100px;
    width         : 100%;
    overflow      : hidden;
    background    : url('../../images/banner_repeat.jpg') repeat-x;
    z-index       : 2;
}
#content {
    position : absolute;
    top      : 100px;
    left     : 0;
    right    : 270px;
    bottom   : 100px;
    overflow : auto;
}
#right_column {
    position   : absolute;
    top        : 0;
    bottom     : 0;
    right      : 0;
    width      : 270px;
    z-index    : 3;
    background : url('../../images/treetrunk7.png') repeat-y;
}
#footer {
    position   : absolute;
    left       : 0;
    bottom     : 0;
    right      : 270px;
    height     : 100px;
    overflow   : hidden;
    background : url('../../images/grass.png') repeat-x;
    z-index    : 2;
}

我将 HTML 的嵌套方式更改为如下:

<div id="banner"> 
    <ul id="banner_ul">
        ...
    </ul>
</div>
    
<div id="content">
    ....
</div>
    
<div id="right_column">tree</div>

<div id="footer">grass</div>

上面代码的效果是 #header 元素位于顶部,#内容元素位于左侧并垂直居中,#footer 元素位于底部,#right_column 元素位于页面右侧。当内容溢出时,#content 元素会获得滚动条,并且滚动条会直接应用于该元素。

奖励回合

当页面太窄时,您可以使用 CSS 媒体查询隐藏右列:

@media all and (max-width: 500px) {
    #right_column {
        display : none;
    }
    #content, #banner, #footer {
        right : 0;
    }
}

这是一个演示: http ://jsfiddle.net/Wyvk8/1/(如果您使页面宽度小于 500 像素,右栏将会消失,仅在支持媒体查询的浏览器中)

Here is a demo: http://jsfiddle.net/Wyvk8/

I removed your inline CSS styles and applied them via CSS rules as follows:

html, body {
    height     : 100%;
    min-height : 100%;
}
#banner {
    position      : absolute;
    top           : 0;
    left          : 0;
    height        : 100px;
    width         : 100%;
    overflow      : hidden;
    background    : url('../../images/banner_repeat.jpg') repeat-x;
    z-index       : 2;
}
#content {
    position : absolute;
    top      : 100px;
    left     : 0;
    right    : 270px;
    bottom   : 100px;
    overflow : auto;
}
#right_column {
    position   : absolute;
    top        : 0;
    bottom     : 0;
    right      : 0;
    width      : 270px;
    z-index    : 3;
    background : url('../../images/treetrunk7.png') repeat-y;
}
#footer {
    position   : absolute;
    left       : 0;
    bottom     : 0;
    right      : 270px;
    height     : 100px;
    overflow   : hidden;
    background : url('../../images/grass.png') repeat-x;
    z-index    : 2;
}

And I changed how your HTML is nested to be like this:

<div id="banner"> 
    <ul id="banner_ul">
        ...
    </ul>
</div>
    
<div id="content">
    ....
</div>
    
<div id="right_column">tree</div>

<div id="footer">grass</div>

The effect of the above code is that the #header element is positioned at the top, the #content element is on the left and centered vertically, the #footer element is positioned at the bottom, and the #right_column element is positioned on the right side of the page. The #content element gets scroll-bar when it's content overflows and the scroll-bar is applied directly to the element.

BONUS ROUND

You can hide the right column when the page is too narrow using CSS media queries:

@media all and (max-width: 500px) {
    #right_column {
        display : none;
    }
    #content, #banner, #footer {
        right : 0;
    }
}

Here is a demo: http://jsfiddle.net/Wyvk8/1/ (if you make the page less than 500px wide the right column will disappear, only in browsers that support media queries)

香草可樂 2025-01-05 08:02:05

您需要将 position:fixed 应用到您的顶部横幅,我假设元素 id“banner_ul”。这意味着它将像绝对定位一样位于页面布局之外,但不受滚动的影响;它总是位于 top: 0; left: 0; 相对于浏览器窗口。请记住适当调整其下方的所有容器,以便它们位于窗口顶部的[横幅的高度],否则在页面加载时它们将与横幅重叠。

You need to apply position: fixed to your top banner, I presume element id "banner_ul". This means it will sit outside the page layout like an absolute positioning, however it is unaffected by scrolling; it will always sit top: 0; left: 0; in relation to the browser window. Remember to appropriately adjust all containers below this so they sit [the banner's height] from the top of the window, otherwise they will overlap with the banner when the page loads.

西瑶 2025-01-05 08:02:05

看来您已将横幅 div 包裹在所有元素周围,因此它不会分层在容器 div 的顶部,因为它也会影响该 div,因为它位于横幅 div 的内部。

It seems you have wrapped your banner div arround all the elements and therefor it wont be layered on top of the container div because it affects that div too since its inside of the banner div.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文