Home > Web Front-end > CSS Tutorial > Why Isn\'t My Checkbox Background Color Changing Inside a Scrolling DIV?

Why Isn\'t My Checkbox Background Color Changing Inside a Scrolling DIV?

Barbara Streisand
Release: 2024-11-29 17:22:11
Original
290 people have browsed it

Why Isn't My Checkbox Background Color Changing Inside a Scrolling DIV?

CSS "background-color" Attribute Not Working on Checkbox within

When attempting to apply a background color to checkboxes contained within a scrolling

, users may encounter an issue where the "background-color" attribute appears to have no effect. Paradoxically, other CSS attributes like "margin-top" function as expected.

This discrepancy arises because checkboxes natively lack the ability to display background color. To achieve the desired effect, wrap each checkbox within a

that possesses the desired background color.

Revised CSS Example:

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

.oddRow,
.evenRow {
  margin-top: 5px;
}

.oddRow {
  border: 1px solid #333;
  background-color: #FFFFFF;
}

.evenRow {
  border: 1px solid #333;
  background-color: #9FFF9D;
}
Copy after login

Revised HTML Example:

<div>
Copy after login

By wrapping each checkbox in a

with the appropriate background color, the desired visual effect can be achieved, bypassing the inherent limitation of checkboxes regarding background color.

The above is the detailed content of Why Isn\'t My Checkbox Background Color Changing Inside a Scrolling 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