Home >Web Front-end >CSS Tutorial >How Can I Make a Floated Div Expand to the Height of Its Parent?
Expanding Floated Div Height to Match Parent
Floating child elements can disrupt the vertical alignment of parent containers. To address this issue and ensure that the height of a floated child div expands to match its parent, follow these steps:
1. Set Parent Properties:
Add the following CSS properties to the parent element:
.parent { overflow: hidden; position: relative; width: 100%; }
2. Configure Floated Child:
For the floated child div (e.g., .child-right), apply the following CSS properties:
.child-right { background: green; height: 100%; width: 50%; position: absolute; right: 0; top: 0; }
By implementing these CSS properties, the floated child div will automatically expand its height to match that of its parent, ensuring a vertically aligned layout.
The above is the detailed content of How Can I Make a Floated Div Expand to the Height of Its Parent?. For more information, please follow other related articles on the PHP Chinese website!