Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set div width equal to window size

Tags:

html

css

width

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%
}`
like image 983
Ruthra Avatar asked Dec 24 '13 14:12

Ruthra


People also ask

How do I make div width auto adjust?

Using width, max-width and margin: auto; Then, you can set the margins to auto, to horizontally center the element within its container. The element will take up the specified width, and the remaining space will be split equally between the two margins: This <div> element has a width of 500px, and margin set to auto.


1 Answers

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

like image 50
NoobEditor Avatar answered Oct 13 '22 05:10

NoobEditor