Personalized border color for radio buttons

What is the best way to change the color of my radio button along with its border color when the radio button is selected?

My code is functioning properly, except for the border color when the radio button is selected. Below is the CSS code that I have added for :after and :before elements.

CSS3:

.planItem [type="radio"]:checked,
.planItem [type="radio"]:not(:checked) {
    position: absolute;
    left: -9999px;
}
.planItem [type="radio"]:checked + label,
.planItem [type="radio"]:not(:checked) + label
{
    position: relative;
    padding-left: 38px;
    cursor: pointer;
    line-height: 20px;
    display: inline-block;
    color: #666;
}
.planItem [type="radio"]:checked + label:before,
.planItem [type="radio"]:not(:checked) + label:before {
    content: '';
    position: absolute;
    left: 15px;
    top: 10px;
    width: 15px;
    height: 15px;
    border: 1px solid #ddd;
    border-radius: 100%;
    background: #fff;
}
.planItem [type="radio"]:checked + label:after,
.planItem [type="radio"]:not(:checked) + label:after {
    content: '';
    width: 9px;
    height: 9px;
    background: #0086D6;
    position: absolute;
    top: 13px;
    left: 18px;
    border-radius: 100%;
    -webkit-transition: all 0.2s ease;
    transition: all 0.2s ease;
}

/* Rest of the CSS code remains unchanged */

JSX:

<div className = "planItem">            
{
    this.state.planItems && this.state.planItems.map(function (smsType, i){
        return <div className={smsType.id} key={i}><input type="radio" id={smsType.id} name="radio-group-menu" onClick={() => this.planhandleClick(smsType.id)}/> 
            <label className="mb-0" htmlFor={smsType.id}>{smsType.name}</label>  
        </div>
    }, this)
}
</div>

Is there a way to achieve the desired border color effect as shown in the following image? https://i.sstatic.net/Wam7i.png

Answer №1

Apply a border of 1px solid #0086D6; to the radio button when it is selected:

.planItem [type="radio"]:checked + label:before {
    border: 1px solid #0086D6;
}

I trust this information proves useful for you.

Answer №2

Feel free to take a look at the example code. I have implemented a hover effect for the overall container using label:hover. When hovering over the radio buttons, different styles are applied based on whether they are checked or unchecked. If the radio is hovered over and unchecked, the following style is applied:

.planItem [type="radio"]:hover + label:before{
  border-color: #04acec;
}
. On the other hand, if the radio button is selected, a border is added to the label as shown below:
.planItem [type="radio"]:checked + label::before {
border-color: #04acec;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Hide HTML div on click

Why does the button disappear when I click on it, but the status refreshes? Javascript $( ".refreshstatus" ).click(function(){ $( ".navplayers" ).load('stats.php'); }); CSS .refreshstatus{ font-family:'Noto Sans'; font-w ...

When the enter key is pressed in a contenteditable div, line breaks are disregarded

Is there a way to ensure that when the return key is pressed to start a new line for a post, the output actually starts on a new line? I've been having trouble with this and would like to know the most common solution. Check out the demo below for te ...

Create a visual representation by converting it into an HTML table

Check out my JSFiddle here: http://jsfiddle.net/0r16e802/4/ I'm attempting to display an image as an HTML table, but I'm facing two major issues with my algorithm: Only the first image is loaded in the first row and I need to figure out how to ...

The prop type `cellHeight` provided to `GridList` in (Material-ui / React) is invalid

warning.js:33 Warning: The prop type for cellHeight in the GridList component is invalid. I encountered this error message, despite the property functioning correctly. Is there a way to resolve this issue? If you're interested, check out the documen ...

JSX conditional rendering not behaving unexpectedly

Having difficulty with a conditional JSX statement causing an element to not display properly unless the window is resized. Please note that it works fine in development mode but does not show correctly after building. The goal is to show navigation links ...

Is there a way to remove the red underlines on warnings in VSCode?

Lately, I have been facing a new problem with my personal computer at home. It seems to have started when I began using React. I'm wondering if the issue has something to do with package.json or eslint config files like settings.json or .eslintrc.cjs. ...

The data table appears to be malfunctioning when the table collapses

Having trouble with the data table when adding a collapse tr. Removing the collapse tr fixes the data table issue. Any help on how to resolve this would be appreciated. $('.tableToggleUl').parent('td').css('padding','0 ...

Ways to arrange specific columns within a table

I am facing an issue with aligning text in a table properly. In my table, I have two columns - first column and second column, both with colspan="4": It is supposed to look like this: <tr> <td colspan="4"> First column </td> ...

What is the best method to erase data from an AutoComplete Box when clicking?

I have incorporated the Material UI AutoComplete component which can be found here. Below is my code snippet: <Autocomplete open={showUniSuggs} onOpen={this.props.getUniversityOptions} onChange={(event, value) => this.props.handleUniversi ...

Guide on implementing iterative data path in v-for loop using Vue

I'm just starting out with Vue and I want to use image file names like "room1.jpg", "room2.jpg", "room3.jpg" in a loop Below is my code, where the second line seems to be causing an issue <div v-for="(p,i) in products" :key="i"> <img src ...

Persistent hover effect for collapsible accordion panels when closing them

My simple accordion features a functionality where a class of .open is added to the title + content group when you open a panel for styling purposes. Everything works smoothly, but I've noticed on my phone that after clicking to close a panel, the hov ...

What are some strategies for optimizing React performance when managing controlled input from numerous components?

Building a Parent component with multiple child components, each passing data to the parent for an API call. The structure is as follows: const MainComponent = () => { const [child1input, setChild1Input] = useState(""); const [child2input, setChild ...

JavaScript Error Caused by Newline Characters

I'm facing an issue with extracting data from a textbox using JavaScript. What I'm attempting to do is retrieve the value from a textbox, display it in an alert, and then copy it. Here's the current code snippet: var copyString = "Date: < ...

Facing challenges with integrating the stripe payment gateway within the strapi content management system

I recently developed an e-commerce website using Next.js, with Strapi as the CMS and Stripe for payment processing. Within the Strapi backend application, I integrated the API required for handling payments. Below is the code snippet: 'use strict&apos ...

What causes the disparity between Chrome's print preview and printed output? [HTML - CSS]

In my Angular demo project, I have included basic text and a table. There is a print button that calls window.print() to print the page with applied styling. printPage() { window.print(); } CSS: @media print { @page { size: landscap ...

Is it possible to submit a select menu without using a submit button within a loop?

I'm having an issue with my code that submits a form when an option in a select box is clicked. The problem arises when I try to put it inside a loop, as it stops working. Can anyone assist me with this? Below is the code snippet causing trouble: &l ...

GATSBY | MATERIAL UI | BUILD ERROR | WebpackError: ReferenceError: document is not defined in gatsby-plugin-material-ui plugin

Just started building a website for a friend using Gatsby 4.0 and decided to go with the material UI template. It looks great and functions well in development. However, when I try to build it, I encounter the following errors. I suspect it has something ...

How can I show information on the same page as a link by simply clicking on it?

My goal is to create a functionality where clicking on a link will display specific information. Currently, all the links and their corresponding information are displayed at once. I want to change this so that the links are displayed first, and the inform ...

When executing a JavaScript program, an error with the message 'MODULE_NOT_FOUND' appeared, causing the internal module loader in Node to throw an error at line 1145

node:internal/modules/cjs/loader:1145 throw err; ^ Error: Module 'C:\Users\sande\3D Objects\JavaScript-Lesson\lesson08.js' not found at Module._resolveFilename (node:internal/modules/cjs/loader:1142:15) at Mo ...

Relative positioning can break the background-clip attribute for text elements

I am experimenting with using background-clip: text on an element that contains some child <p> elements. I wanted to enhance the design by adding some absolutely positioned :after elements to the <p> tags, covering up the text for animation eff ...