Html 阻止 div 容器调整大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13788192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:17:01  来源:igfitidea点击:

Stop div container from resizing

htmlcssresize

提问by A H

I have two columns in an html page, one is floated right and the other is floated left. I have set the height of both containers to 100% and the width of both containers to 50%. I want the two containers to fit the entre window. When the user re-sizes the window horizontally I don't want the content to resize. How can i achieve this?

我在 html 页面中有两列,一列向右浮动,另一列向左浮动。我已将两个容器的高度设置为 100%,将两个容器的宽度设置为 50%。我希望两个容器适合主窗口。当用户水平调整窗口大小时,我不希望内容调整大小。我怎样才能做到这一点?

Thanks

谢谢

回答by Yann Chabot

There is many way to achieve that. First of all, the easiest would be to put the css value min-width! So if you want it to resize but to stop at 960px (for example) you just have to do :

有很多方法可以实现这一目标。首先,最简单的方法是将 css 值设为 min-width!因此,如果您希望它调整大小但停止在 960 像素(例如),您只需要执行以下操作:

    myCoolDiv{
         width: 100%;
         height: 50%;
         min-width: 960px;
   }

That would give you the best result. Else, if you dont want content to resize at all, and the selector to have a width equal to 100% of the initial screen, I would use jQuery that way:

那会给你最好的结果。否则,如果您根本不希望内容调整大小,并且选择器的宽度等于初始屏幕的 100%,我会以这种方式使用 jQuery:

    $(document).ready(function() {
       //Call a variable to know the width of the window
       var screenWidth = $(window).width();
       $('myCoolDiv').css('width', screenWidth + 'px');
    });

Hope it helped! Tell me if my answer is not clear enough or if you don't understand a part of it!

希望有帮助!如果我的回答不够清楚或者您不了解其中的一部分,请告诉我!

Cheers!

干杯!