The style of the check box control for a checkbox in a pure CSS setting

Source: Internet
Author: User

Here are the five simple styles of the pure CSS Settings checkbox control, which you can change to become the style you want.

First, you need to add a section of CSS to hide all checkbox checkboxes, and we'll change the look. To do this, you need to add a piece of code to your CSS file.

After hiding all of the checkbox checkboxes, we need to add a label HTML element, and we all know that when clicked on a label label with the For property, the checkbox for the checkbox is selected. This means that we can use the label's click event to process our checkbox check box.

Style One

This check box style is like an unlock slider, and the sliders are checked and unchecked to show different positions. When you click the Slider button (label label), the check box is selected, and then the slider moves to the on position.

We start creating the HTML for the check box area.

Because this style check box, a label is not enough to complete the task, we use a DIV element to include a checkbox, we need to use them for black bands and fillets.

Now we can put the label as a slider on the stripe, we want the button effect to move from one side of the strip to the other, and we can add a label transition.

Now that the slider is in the selected (closed) position, when we select the check box, we want a reaction to occur, so we can move the slider to the other end. We need to know that the Judge check box is selected and if so, the left property of the label element is changed.

This is the CSS for the first checkbox you need.

Style Two

This check box is styled like a style, but unlike this, the slider button changes color. When you click the slider button, it moves to the other side of the strip and changes the color of the button.

The HTML code and style one are exactly the same.

This div becomes a bit larger than the style, and the label remains as a slider, using the CSS below to define it.

There is a black bar in the middle of the pattern, and the slider slides around it, but the DIV element is already in use, so we need to create a new element with: before Pseudo-class.

As with style one, next we write a CSS style for the label and use it as a slider.

I want to implement the same selection as the style, change the left and background properties of the label when it is selected.

Style Three

The check box style is more complex than the style two, it slides right and left as in the previous example, and when you change the selected and unchecked states, the slider slides to the other side and displays the corresponding text in the original position.

First, we write the HTML code, which is the same as before.

Then we use the DIV as the slider in the same way, and the code below creates a black rounded stripe, where we can put the slider and the text inside.

When the slider is unchecked, the slider is on the left and "OFF" appears on the right, and when clicked, the slider moves to the right and "on" appears on the left.
But the number of elements is not enough to allow us to implement these functions, so we will use: Before and: After two pseudo-classes to create two elements, respectively, put "on" and "OFF".

As before, let's add the slider style, which moves to the other side when clicked, and changes the color.

Style Four

In this style, we create two circles that change the color of the circle inside when clicked to indicate the selected and unchecked state.
The same HTML code as before.

Next we create the outer circle for the checkbox, use the CSS's Border-radius property, and set it to 100% to create a positive circle.

We then use the LABEL element to create a smaller circle, which changes color according to the checkbox state.

Style Five

This check box has a different style, it looks just a little bit better than the default checkbox style of the browser, but the difference is that we can define its style according to our own needs.
First, it's the same HTML code.

In the previous example, we used the div as a slider or an outer circle for the checkbox, but this time we don't need to use the DIV element to set the area of the check box.

The label label is used for the Click event and the box style for the check boxes we want to define.

Next, we'll create a tick in the box, for which we can create a new element using the after pseudo-class, and to implement this style, we can create a 5px x 9px rectangle and give him a border. When we remove the top and right border, it will look like a letter L. Then we can use the CSS's Transform property to rotate it so that it looks like a tick.

In the above CSS, we have set its transparency to 0.2, so you will see a check box with a translucent checkmark. You can deepen a little while hovering, and when selected, you can set it to opaque.

This will create a new checkbox style for you.

The style of the check box control for a checkbox in a pure CSS setting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.