using percent
suggest changePercentages are useful units when creating a responsive layout.
A percentage width is resolved against the containing block's width.
Equation:
(parent container's width) * (percentage) = output
For Example:
Parent has 100px width while the Child has 50%.
On the output, the Child’s width will be half(50%) of the Parent’s, which is 50px.
HTML
<div class="parent">
PARENT
<div class="child">
CHILD
</div>
</div>
CSS
*{
color: #CCC;
}
.parent{
background-color: blue;
width: 100px;
}
.child{
background-color: green;
width: 50%;
}
OUTPUT
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents