Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Div containing floating left items doesn't expand properly

Tags:

html

<div id="DateAndTime" style="clear:left; width:100%" class="Frame">
<h2>Date & Time Criteria</h2>
<h3>Permitted Days of the Week</h3>
<p class="DataForm" style="float:left">

<asp:CheckBox id="chkMonday" runat="server" Text="Monday"/><br />
<asp:CheckBox id="chkTuesday" runat="server" Text="Tuesday"/><br />
<asp:CheckBox id="chkWednesday" runat="server" Text="Wednesday"/><br />
<asp:CheckBox id="chkThursday" runat="server" Text="Thursday"/><br />
<asp:CheckBox id="chkFriday" runat="server" Text="Friday"/><br />
<asp:CheckBox id="chkSaturday" runat="server" Text="Saturday"/><br />
<asp:CheckBox id="chkSunday" runat="server" Text="Sunday"/><br />
</p>
<p class="DataForm" style="float:left">
<asp:CheckBox id="CheckBox1" runat="server" Text="Monday"/><br />
<asp:CheckBox id="CheckBox2" runat="server" Text="Tuesday"/><br />
<asp:CheckBox id="CheckBox3" runat="server" Text="Wednesday"/><br />
<asp:CheckBox id="CheckBox4" runat="server" Text="Thursday"/><br />
<asp:CheckBox id="CheckBox5" runat="server" Text="Friday"/><br />
<asp:CheckBox id="CheckBox6" runat="server" Text="Saturday"/><br />
<asp:CheckBox id="CheckBox7" runat="server" Text="Sunday"/><br />
</p>

<p style="clear:left">&nbsp</p>
</div>

If I remove the last <p style="clear:left"> line, the div does not stretch to enclose the checkboxes. Is there a better way to force it to expand than this?

like image 444
NibblyPig Avatar asked Dec 30 '25 08:12

NibblyPig


1 Answers

Yes, that's how CSS works. There are workarounds (my preferred one, another approach) to allow a parent to specify that it will expand to contain its floats.

like image 124
bobince Avatar answered Jan 02 '26 00:01

bobince



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!