Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Div 100% of grandparent container?

Tags:

css

Here's the problem I have:-

I have one div that is set to a max width of 960px.

The width of the div inside the div is set to 100%, but 100% means a max of 960px

How can I make the div inside the 960px div become 100% of the user's screen, without moving the child div(100%) out of the parent div(960px)?

EDIT FOR FURTHER CLARIFICATION. Here's the structure:-

 gParentDiv     parentDiv        myDiv 

I want myDiv to be the same width as gParentDiv, but keep it within parentDiv

I hope you can help

like image 766
BenjaminFranklin Avatar asked Sep 15 '13 16:09

BenjaminFranklin


People also ask

How do you make a div full width of a parent?

Method 2: We can make the display attribute of the child container to table-row and display attribute of parent container to table, that will take all the height available from the parent div element. To cover all the width, we can make the width of parent div to 100%.

How do you make a div take up the full height of a parent?

Answer: Set the 100% height for parents too And we all know that the default value of the height property is auto , so if we also set the height of <body> and <html> elements to 100%, the resulting height of the container div becomes equal the 100% height of the browser window.

How do I make DIVS always fit in my parent div?

If you want the child divs to fit the parent size, you should put a margin at least of the size of the child borders on the child divs ( child. margin >= child.

How do I make a div only as large as content?

Answer: Use the CSS display Property You can simply use the CSS display property with the value inline-block to make a <div> not larger than its contents (i.e. only expand to as wide as its contents).


1 Answers

You can use the viewport's height and width.

For example, the following class will make the element the size of the viewport.

.fullscreen {     width: 100vw;     height: 100vh; } 

jsFiddle Demo

This is a pure CSS3 solution, but it has some browser support issues.


If you just want to strech an element on the entire screen you can use a different approach.

jsFiddle Demo

.fullscreen {     position: absolute;     top: 0;     left: 0;     bottom: 0;     right: 0; } 
like image 154
Itay Avatar answered Oct 05 '22 23:10

Itay