将div宽度设置为等于窗口大小 [英] Set div width equal to window size

查看:1805
本文介绍了将div宽度设置为等于窗口大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个宽度为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宽度设置为等于窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆