Home > Web Front-end > CSS Tutorial > Why Doesn\'t Background Color Apply to Checkboxes in a Scrollable Div?

Why Doesn\'t Background Color Apply to Checkboxes in a Scrollable Div?

Susan Sarandon
Release: 2024-11-29 08:42:10
Original
658 people have browsed it

Why Doesn't Background Color Apply to Checkboxes in a Scrollable Div?

CSS 'background-color' Attribute Issue with Checkboxes in a Div

Despite setting the 'background-color' attribute in CSS for checkboxes within a scrollable div, the background color modification is not being applied. However, other attributes like 'margin-top' work as expected.

The HTML and CSS code the user provided is as follows:

HTML:

<div>
Copy after login
Copy after login

CSS:

.listContainer {
    border:2px solid #ccc;
    width:340px;
    height: 225px;
    overflow-y: scroll;
    margin-top: 20px;
    padding-left: 10px;
}

.oddRow {
    margin-top: 5px;
    background-color: #ffffff;
}

.evenRow{
    margin-top: 5px;
    background-color: #9FFF9D;
}
Copy after login

Explanation:

The issue arises because checkboxes do not natively support the 'background-color' attribute. To create the desired visual effect, you must wrap each checkbox within a div element and assign the color to that div instead.

Revised HTML:

<div>
Copy after login
Copy after login

Revised CSS:

.listContainer {
    /* Same as before */
}

.oddRow, .evenRow {
    /* Remove incorrect background-color */
}

.evenRow {
    background-color: #9FFF9D;
}

.oddRow {
    background-color: #ffffff;
}
Copy after login

The above is the detailed content of Why Doesn\'t Background Color Apply to Checkboxes in a Scrollable Div?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template