简体   繁体   English

如何将div宽度设置为100%

[英]How to set div width to 100%

I'm trying to design a 2 column layout using divs. 我正在尝试使用div设计2列布局。 My left column size is fixed to 150 px . 我的左列大小固定为150 px But right column is not fixed size, so I want it to extend to right boundary of the browser. 但是右列的大小不是固定的,因此我希望它扩展到浏览器的右边界。 I used width:auto and width:100% values in right column but they didn't work. 我在右栏中使用了width:autowidth:100%值,但是它们没有用。

CSS : CSS:

  html { height:100%; width:100% } body { color: #000040; text-align: left; padding:0; margin:0; height:100%; width:100% } #header { position:relative; float:left; background-color: #000053; width: 100%; height: 76px } #wrapper { position:relative; overflow:hidden; width:100%; height: 100%; margin:0px auto; padding:0; background-color:Aqua } #container { clear:left; float:left; overflow:hidden; width:100%; height:100% } #left_column { position: relative; float: left; background-color:Fuchsia; width: 150px; overflow:hidden; height:100% } #right_column { position: relative; float:left; overflow:hidden; background-color:Blue; height: 100%; width:auto } 

HTML HTML

<html>
    <body>
        <div id="wrapper"> 
            <div id="header">
               HEADER
            </div>
            <div id="container">
                <div id="left_column">
                    LEFT COLUMN
                </div>
                <div id="right_column">
                    RIGHT COLUMN
                </div>
            </div>
        </div>
    </body>

</html>

I would remove all position statements and only put a float:left on the left column, not the right nor the container. 我将删除所有position语句,只将float:left放在左列上,而不是right或容器上。 Give the right column a margin-left:150px and it should work fine. 给右边的列margin-left:150px一个margin-left:150px ,它应该可以正常工作。

Except for the left-floated column, you can also remove the width:100% statements from the rest; 除了左浮动列外,您还可以从其余部分中删除width:100%语句; when they're not floated, they'll be 100% wide automatically. 当它们不漂浮时,它们会自动100%宽。

The overflow:hidden is only needed on the wrapper; 只在包装器上需要overflow:hidden at least if you are using it to have the div grow in height to accommodate the floats inside it. 至少如果您使用它来使div的高度增加以容纳其中的浮子。

change for the div right_column the position from relative to fixed, and width from auto to 100%. 将div right_column的位置从相对更改为固定,将宽度从auto更改为100%。 Also add left:150px; 还要加上left:150px; With these changes you css for right_column will look like the following: 进行了这些更改后,您的right_column的css将如下所示:

#right_column {
        position: fixed;
        left:150px;
        float:left;
        overflow:hidden;
        background-color:Blue;
        height: 100%;
        width:100%; }

you can check it here http://jsbin.com/ejetu3 您可以在这里检查它http://jsbin.com/ejetu3

有没有办法设置<div>宽度到屏幕的 100%?</div><div id="text_translate"><p> 我有一个纯 HTML /CSS 网页。 我制作了一个下拉菜单,但无法将其设置为全宽。</p><p> 这是它的代码笔。</p><p> <a href="https://codepen.io/SynergyOfLife/pen/ExyZdZz" rel="nofollow noreferrer">https://codepen.io/SynergyOfLife/pen/ExyZdZz</a></p><p> 我正在使用 Bootstrap 4.5.2。</p><p> 无论我尝试什么,我的.header div 都不会填充 100% 的宽度。 我希望它填充 100%,下面是示例文本。</p><p> 帮助将不胜感激,谢谢。</p></div> - Is there a way to set the <div> width to 100% of the screen?

暂无
暂无

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

相关问题 当jQuery第二个div隐藏时如何将div的宽度设置为100% - How to Set width of div to 100% when second div hide by jQuery 如果 DIV 位于可滚动的父 DIV 中,如何将其宽度设置为 100%? - How to set width of a DIV to 100% if it is in a scrollable parent DIV? 设置Div宽度100%但有边距 - Set Div Width 100% But With Margin 将div宽度设置为100%并将其固定为该宽度 - Set div width to 100% and fix it at that width 当父级溢出时,如何将子级div宽度设置为100%? - How to set Child div width 100% while parent over flow? 如何使2 div的宽度为100% - how to make 100% width for 2 div 有没有办法将子div的宽度设置为浏览器的100%? - Is there a way to set the width of a child div to 100% of the browser? 有没有办法设置<div>宽度到屏幕的 100%?</div><div id="text_translate"><p> 我有一个纯 HTML /CSS 网页。 我制作了一个下拉菜单,但无法将其设置为全宽。</p><p> 这是它的代码笔。</p><p> <a href="https://codepen.io/SynergyOfLife/pen/ExyZdZz" rel="nofollow noreferrer">https://codepen.io/SynergyOfLife/pen/ExyZdZz</a></p><p> 我正在使用 Bootstrap 4.5.2。</p><p> 无论我尝试什么,我的.header div 都不会填充 100% 的宽度。 我希望它填充 100%,下面是示例文本。</p><p> 帮助将不胜感激,谢谢。</p></div> - Is there a way to set the <div> width to 100% of the screen? 将DIV宽度和高度设置为100%,并且不要调整其大小 - Set DIV width and height to 100% and do not resize it 将固定div设置为父容器的100%宽度 - Set a Fixed div to 100% width of the parent container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM