Home >Web Front-end >CSS Tutorial >Why Doesn\'t `background-color` Work on Checkboxes Inside a Scrollable Div?
CSS "background-color" Attribute Not Working on Checkboxes Within The issue highlighted in the inquiry is the inability of the "background-color" attribute to affect checkboxes enclosed within a scrollable div. While attributes like "margin-top" function as expected, "background-color" remains ineffective. To understand this behavior, it's important to note that checkboxes inherit their background color from their parent elements. By default, the base background color for checkboxes is dependent on the browser's styling. Thus, it's not possible to directly set the background color of a checkbox itself. To provide the desired effect, an alternative approach can be taken by wrapping each checkbox within a div element that possesses the desired background color. This way, the div element will hold the checkbox and serve as a proxy for setting the background color. For instance: The above is the detailed content of Why Doesn\'t `background-color` Work on Checkboxes Inside a Scrollable Div?. For more information, please follow other related articles on the PHP Chinese website!<div class="evenRow">
<input type="checkbox" />
</div>
<div class="oddRow">
<input type="checkbox" />
</div>
<div class="evenRow">
<input type="checkbox" />
</div>
<div class="oddRow">
<input type="checkbox" />
</div>
.evenRow {
background-color: #9FFF9D;
}
.oddRow {
background-color: #ffffff;
}