将div宽度设置为等于窗口大小

编程入门 行业动态 更新时间:2024-10-28 20:22:44
本文介绍了将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宽度设置为等于窗口大小

本文发布于:2023-07-29 08:26:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1239063.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:设置为   宽度   大小   窗口   div

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!