Consider the HTML code provided below:
<!DOCTYPE html>
<html>
<body>
<div id="parent" style="border:1px solid #666;width:600px;height:200px;padding:5px;">
<div id="child1" style="border:1px solid #666;float:left;margin-left:10px;display:inline-block;">How<br>are<br>you?</div>
<div id="child2" style="border:1px solid #666;float:left;margin-left:100px;">How are you?</div>
<div id="child3" style="border:1px solid #666;float:right;margin-right:40px;">How are you?<br>How are you?<br>How are you?</div>
</div>
</body>
</html>
Is there a way to align the three child divs in the center of the parent div, as shown in the example screenshot?
https://i.sstatic.net/hpIfq.png
The height of the child divs may vary due to changing text content, making it challenging to use properties like top
, margin-top
, and position:absolute
. Constantly adjusting the values is not feasible. Are there alternative methods to achieve this alignment without fixed heights?