简体   繁体   English

阻止div容器调整大小

[英]Stop div container from resizing

I have two columns in an html page, one is floated right and the other is floated left. 我在html页面中有两列,一列是向右浮动,另一列是向左浮动。 I have set the height of both containers to 100% and the width of both containers to 50%. 我已将两个容器的高度设置为100%,两个容器的宽度设置为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? 我怎样才能实现这一目标?

Thanks 谢谢

There is many way to achieve that. 有很多方法可以实现这一目标。 First of all, the easiest would be to put the css value min-width! 首先,最简单的方法是将css值设为min-width! So if you want it to resize but to stop at 960px (for example) you just have to do : 因此,如果您希望它调整大小但停止在960px(例如),您只需要:

    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! 干杯!

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

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