I need the following div to have a background color - simple right. But, it doesn't work correctly. I've done some testing, and figured out its the floats on the spans that are screwing it up. So, how do i fix this?
.days{
background-color:#000;
}
span {
display:block;
width:200px;
float:left;
}
<div class="days">
<span>
<input id="Field9" name="Field9" type="checkbox" value="" size="3" maxlength="4" tabindex="4" />
<label class="days" >Monday</label>
</span> <span>
<input id="Field5" name="Field10" type="checkbox" value="" size="3" maxlength="4" tabindex="4" />
<label class="days" >Tuesday</label>
</span> <span>
<input id="Field5" name="Field11" type="checkbox" value="" size="3" maxlength="4" tabindex="4" />
<label class="days" >Wednesday</label>
</span> <span>
<!-- goes till sunday --!>
</div>
Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side. float:right; This property is used for those elements(div) that will float on right side.
Absolutely positioned page elements will not affect the position of other elements and other elements will not affect them, whether they touch each other or not. There are four valid values for the float property. Left and Right float elements those directions respectively.
Assuming that your . png file actually exists, try setting the background size and repeat tags. If that doesn't work, try checking in your browser's developer tools for the response codes and making sure that the url is correct.
When you float elements, you take them out of the normal flow of the document, and as a result, other non-floated elements do not make room for them.
What you're observing is that your div no longer takes the full height of its child elements because they're floated. All you need to do is to "clear" or undo the floating, and make days
take the full height, and its background color will show. My preferred way of clearing floats is to give your containing element overflow: hidden
:
.days
{
background-color:#000;
overflow: hidden;
}
For more info about clearing floats, check out the Quirksmode.org article about it, which includes an explanation of the overflow: hidden
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With