简体   繁体   English

如何扩展div的正确宽度?

[英]How to expand the right width of a div?

I want to expand the right width of a div to 100% (look at the screenshot, my div is red), I have tried with: 我想将div的正确宽度扩展到100%(请看截图,我的div是红色的),我已经尝试过:

HTML example: HTML示例:

<header>
    <nav>
        <ul>
            <li>Menu</li>
            <li>Menu</li>
            <li>Menu</li>
        </ul>
    </nav>
    <aside>
        <h1>Logo</h1>
    <aside>
</header>

CSS: CSS:

header {
    width: 1024px;
    height: 395px;
    margin: 0 auto;
}

nav {
    height: 60px;
    width: 690px;

    position: absolute;
    top: 20px;
    right: 0;

    background:red;
}

This works fine but when i try to zoom out (ctrl -) the menu navigation list go out from the container. 这工作正常,但当我尝试缩小(ctrl-)时,菜单导航列表将从容器中移出。 The logo remains centered but nav not. 徽标保持居中,但没有。

Thanks for any help! 谢谢你的帮助!
and sorry for my bad english. 对不起,我的英语不好。

点击这里

I think you are looking for this: jsfiddle . 我认为您正在寻找这个: jsfiddle Put position: relative to your header. 放置position: relative对于标头。 After that your nav's positioning will behave relative to your header. 之后,您的导航仪的定位将相对于标头进行。 And for the correct alignment change your nav's top: 20px to top: 0 . 为了正确对齐,请将导航的top: 20px更改为top: 0

If you want that red bar will always extend to the right margin of window, even if you enlarge and narrow the Browser window, you can set width of this bar to a very high value (for example 500%). 如果您希望红色条始终延伸到窗口的右边距,即使您放大和缩小“浏览器”窗口,也可以将该条的宽度设置为很高的值(例如500%)。 This will extend bar a lot to right but will add an horizontal scrollbar. 这会将条形图向右延伸很多,但会添加一个水平滚动条。 So set the following to simply hide overflow: 因此,设置以下内容以简单地隐藏溢出:

html,body
{
   overflow-x:hidden;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM