我有一个宽度为1300像素的容器。在容器内部我有其他div。 我需要设置内部div宽度等于浏览器窗口大小例如)1900px。 内容应该响应窗口大小。
I have a container of width 1300 px. Inside the container i have other div. I need to set the inner div width equal to browser window size eg) 1900px. The content should be responsive to the window size.
我的html代码如下:
My html code is like below:
<div class="container"> <div class="content">Some style goes here </div> </div>Css:
.container { width: 1300px; } .content{ width: 100% }`推荐答案
如果你在 px 格式的div宽度不响应。 它必须是%格式。如果你把内容设置为 width:100%内部内容的宽度为'.container'。 为了得到内部div是窗口宽度,你应该有 .container 等于窗口宽度。
If you have the div width in px format it wont be responsive. It has to be in % format. If you put the inner content as width:100% The inner content will have a width of the '.container'. So in order to get the inner div to be the window width you should have the .container to be equal to the window width.
CSS:
.container{ width:100%; }或者如果你想我们可以使用jQuery:
Or if you want we can use jQuery:
var w = $(window).width(); $('.content').css('width', w);更多推荐
将div宽度设置为等于窗口大小
发布评论