Hi, Is there any way to downsize div along with it’s content? What I mean for example I would like to set the parent div width and height to 50% and everything inside should downsize accordingly so the layout wont change… any idea how to achieve this ?
- Has been a member for 3-4 years
- Won a Competition
- Contributed a Blog Post
- Author had a File in an Envato Bundle
- Was featured in a podcast
- Interviewed on the Envato Notes blog
- Community Moderator
- Item was Featured
- Author was Featured
- Beta Tester
- Exclusive Author
- Sold between 100 000 and 250 000 dollars
- Bought between 10 and 49 items
- Poland
- Referred between 100 and 199 users
- Has been a member for 3-4 years
- Exclusive Author
- Sold between 100 and 1 000 dollars
- Bought between 10 and 49 items
- Europe
- Referred between 100 and 199 users
If you put width:50%; height:50% on the parent div, wouldn’t width:auto; height: auto; work for the child div(s) ? And you’d probably add some padding if it’s needed.
Of course, you would still need the parent div’s parent to have a width.
- Has been a member for 2-3 years
- Community Superstar
- Author had a Free File of the Month
- Item was Featured
- Author was Featured
- Exclusive Author
- Sold between 100 000 and 250 000 dollars
- Bought between 50 and 99 items
- Austria
- Referred between 200 and 499 users
width and height always rely on their parent element (except you use px of course)
If the child div has a width of 100% (which is the same as ‘auto’) it has always the size of it’s parent (if you don’t set margin or padding)
If you would like to set the parent to 50% and and the child to 50% you have to use inherit> HTML :
<div id="cont">
<div id="parent">
<div id="child">X</div>
</div>
</div>
CSS :
#cont{ /*only to have an absolute container */
width:600px;
height:600px;
background:green
}
#parent{
width:50%; /* is 300px */
height:50%;
background:red;
}
#child{
width:inherit; /* is 150px */
height:inherit;
background:blue;
}
If you don’t use ‘inherit’ width will be ‘auto’ which is 100%
- Has been a member for 3-4 years
- Won a Competition
- Contributed a Blog Post
- Author had a File in an Envato Bundle
- Was featured in a podcast
- Interviewed on the Envato Notes blog
- Community Moderator
- Item was Featured
- Author was Featured
- Beta Tester
- Exclusive Author
- Sold between 100 000 and 250 000 dollars
- Bought between 10 and 49 items
- Poland
- Referred between 100 and 199 users
Thanks guys, I think I already tried that methods but I will do this one more time
Cheers.
