CSS clicks on the radio to switch between two image styles and only one of the multiple radios can be checked

CSS clicks on the radio to switch between two image styles and only one of the multiple radios can be checked

We implement a red image style for the clicked button, and a gray image style for the other unselected buttons. See the following image style:

1. First, I create two radios here: (You can also declare more, the data here is normally obtained dynamically)

<input type="radio" name="defaultAddress" class="address_manager_content-d3-left-img" />
<input type="radio" name="defaultAddress" class="address_manager_content-d3-left-img" />

2. Add style to radio: CSS code:

.address_manager_content-d3-left-img{
 /* Hide the original style */
 appearance: none;
 -webkit-appearance: none;
 outline: none;
 /* Add new style: when not selected*/
 display: inline-block;
 width: 20px;
 height: 20px;
 position: static;
 margin : 15px 5px 0 0!important;
 background: url(/public/app/gzh/images/address_manager_wxz.png) no-repeat;
 background-size: cover;
}
.address_manager_content-d3-left-img:checked{/* When selected*/
   background: url(/public/app/gzh/images/address_manager_xz.png) no-repeat;
   background-size: cover;
}

3. Description: (There are several key styles, other styles can be adjusted by yourself)

1) Hide the original style 2) Replace the original style with the image using the url attribute 3) About! Important usage: This article of mine explains 4) background-size: cover attribute: enlarge the background image to a size that fits the element container. The image proportions remain unchanged, but please note that the part that exceeds the container may be cropped. (Similar to background-size: 100% 100%) 5) Select element: checked to set the selected style.

4. After completing the above steps, you can click the radio to switch the image style. This is part of address management. Click back to use Vue.js to implement address management.

Summarize

The above is the CSS that I introduced to you. Click on the radio to switch between two image styles, and only one of the multiple radios can be checked. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

<<:  Design reference WordPress website building success case

>>:  The difference between method=post/get in Form

Recommend

Analysis of problems caused by MySQL case sensitivity

MYSQL is case sensitive Seeing the words is belie...

Three ways to refresh iframe

Copy code The code is as follows: <iframe src=...

Advantages and disadvantages of conditional comments in IE

IE's conditional comments are a proprietary (...

Solution to the welcome to emergency mode message when booting CentOS7.4

Today I used a virtual machine to do an experimen...

MySQL uses inet_aton and inet_ntoa to process IP address data

This article will introduce how to save IP addres...

HTML form tag tutorial (1):

Forms are a major external form for implementing ...

MySQL binlog opening steps

Binlog is a binary log file that is used to recor...

How to set Tomcat as an automatically started service? The quickest way

Set Tomcat to automatically start the service: I ...

HTML table border control implementation code

Generally, when we use a table, we always give it...

Vue custom component implements two-way binding

Scenario: The interaction methods between parent ...

How to encapsulate axios request with vue

In fact, it is very simple to encapsulate axios i...

XHTML Getting Started Tutorial: Using the Frame Tag

<br />The frame structure allows several web...

Vue globally introduces scss (mixin)

Table of contents 1. mixin.scss 2. Single file us...

The role and opening of MySQL slow query log

Preface The MySQL slow query log is a type of log...