10
votes

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.

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%
}`
6

6 Answers

19
votes

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%;
}

Or if you want we can use jQuery:

 var w = $(window).width();
 $('.content').css('width', w);
10
votes

It looks like you want to open your content div as a modal window, hiding rest of the body elements. Try this JSBIN DEMO

.content {
  position: fixed;
  top: 0;
  left: 0;
  bottom:0;
  right:0;
}
4
votes

change container to

.container {
   width: 100%;
}
3
votes

With a fixed width: 1300px;, you can not have a responsive to the window size div

As codehorse said, add

.container {
   width: 100%;
}

but add

html, body {
    height:100%;
    width:100%;
    margin:0;
    padding:0;
}

to you css as width: 100%; will render correctly if the dimension of the parent elements have been set beforehand!!

working demo

0
votes

remove default(bootstrap) max-width of container and set content width to 100%

.content{
      width: 100%;
}

.contianer{
       max-width: none; 
}
0
votes

You can set the width of the .content (child div) equal (100%) to the browser window size instead of equal (100%) to the .container size (father div):

.container {
   width: 1300px;
} 

.content{
  width: 100vw;
}

1vw is 1% of the width of the viewport