- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Community Moderator
- Author was Featured
- Bought between 10 and 49 items
- Referred between 200 and 499 users
- Has been a member for 4-5 years
- Won a Competition
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 ?
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.
- Microlancer Beta Tester
- Author had a Free File of the Month
- Has been a member for 3-4 years
- Item was Featured
- Author was Featured
- Austria
- Exclusive Author
- 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%
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Community Moderator
- Author was Featured
- Bought between 10 and 49 items
- Referred between 200 and 499 users
- Has been a member for 4-5 years
- Won a Competition
Thanks guys, I think I already tried that methods but I will do this one more time
Cheers.
