How to use css3 to change input single-select and multi-select styles

高洛峰
Release: 2017-03-15 11:32:08
Original
1405 people have browsed it

In project development, we often encounter situations where we need to change the input single-select and multi-select styles. Today I will introduce to you a simple way to change the input single-select and multi-select styles.

Let’s briefly introduce it before this:beforepseudo-class

:before selector inserts content before the selected element . Use the content attribute to specify the content to be inserted (content is required).

I believe this is not difficult to understand. Next, let’s understand the idea first:

(1) First use label to define a mark for the input element in html, that is, when you click the label label The corresponding input will also be selected or deselected

(2) The next step is to write css, hide the input, just add your style before the label, it can be pictureIt can also be a circle drawn by yourself. The example below is the circle I wrote. Of course, it can also be replaced with a background image.

input[type="radio"]+label:before是未选中状态的样式
Copy after login
input[type="radio"]:checked+label:before是选中状态的样式
Copy after login

<input type="radio" id="nationality1"><label for="nationality1">中国</label></p>
Copy after login

{:;
}{:;
}{:;:;:;:;:;:;:;:;:;
}{:;:;:;:;:;:;:;:;:;
}
Copy after login

Replace radio with checkbox to make multiple selections.

Note: Hiding and pseudo-class positioning are key

The above is the detailed content of How to use css3 to change input single-select and multi-select styles. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template