Disabled radio buttons are appearing as if they have been chosen

While working on customizing the styles of radio buttons in a form, I encountered an issue where disabled radio buttons appeared selected even though they were supposed to show as disabled. Here is the code snippet that I used:

    input ::-ms-clear {
        display: none;
    }
    
    .radio {
      margin: 0.5rem;
    }
    .radio input[type="radio"] {
      position: absolute;
      opacity: 0;
    }
    .radio input[type="radio"] ~ .radio-label:before {
      content: '';
      background: white;
      border-radius: 100%;
      border: 1px solid #1c2e4f;
      display: inline-block;
      width: 1.4em;
      height: 1.4em;
      position: relative;
      top: -0.2em;
      margin-right: 1em;
      vertical-align: top;
      cursor: pointer;
      text-align: center;
      -webkit-transition: all 250ms ease;
      transition: all 250ms ease;
    }
    .radio input[type="radio"]:checked ~ .radio-label:before {
      background-color: #3E64AD;
      -webkit-box-shadow: inset 0 0 0 4px white;
              box-shadow: inset 0 0 0 4px white;
    }
    .radio input[type="radio"]:focus ~ .radio-label:before {
      outline: none;
      border-color: #3E64AD;
    }
    .radio input[type="radio"]:disabled ~ .radio-label:before {
      -webkit-box-shadow: inset 0 0 0 4px white;
              box-shadow: inset 0 0 0 4px white;
      border-color: #bfbfbf;
      background: #bfbfbf;
    }
    .radio input[type="radio"] ~ .radio-label:empty:before {
      margin-right: 5em;
    }
    
    .radio-label {
        line-height: 1rem;
    }
     <div>
        <label> Radio buttons </label>
        <div class="col-md-3 radio">
          <label class="radio-inline">
            <input type="radio" value="'NONE'" name="feature1" checked="checked" disabled="disabled"/>
            <span class="radio-label"> OPT I </span>
          </label>
        </div>
         <div class="col-md-3 radio">
          <label class="radio-inline">
            <input type="radio" value="'NONE'" name="feature1" disabled="disabled"/>
            <span class="radio-label"> OPT II </span>
          </label>
        </div>
         <div class="col-md-3 radio">
          <label class="radio-inline">
            <input type="radio" value="'NONE'" name="feature1" disabled="disabled"/>
            <span class="radio-label"> OPT III </span>
          </label>
        </div>
        
      </div>
    
    </body>
    </html>

Everything works fine without any custom styles applied, so I'm seeking assistance to identify the root cause of this unexpected behavior.

Answer №1

Get rid of this specific styling:

.radio input[type="radio"]:disabled ~ .radio-label:before {
  background: #bfbfbf;
}

Code Snippet:

    input ::-ms-clear {
        display: none;
    }
    
    .radio {
      margin: 0.5rem;
    }
    .radio input[type="radio"] {
      position: absolute;
      opacity: 0;
    }
    .radio input[type="radio"] ~ .radio-label:before {
      content: '';
      background: white;
      border-radius: 100%;
      border: 1px solid #1c2e4f;
      display: inline-block;
      width: 1.4em;
      height: 1.4em;
      position: relative;
      top: -0.2em;
      margin-right: 1em;
      vertical-align: top;
      cursor: pointer;
      text-align: center;
      -webkit-transition: all 250ms ease;
      transition: all 250ms ease;
    }
    .radio input[type="radio"]:checked ~ .radio-label:before {
      background-color: #3E64AD;
      -webkit-box-shadow: inset 0 0 0 4px white;
              box-shadow: inset 0 0 0 4px white;
    }
    .radio input[type="radio"]:focus ~ .radio-label:before {
      outline: none;
      border-color: #3E64AD;
    }
    .radio input[type="radio"]:disabled ~ .radio-label:before {
      -webkit-box-shadow: inset 0 0 0 4px white;
              box-shadow: inset 0 0 0 4px white;
      border-color: #bfbfbf;
    }
    .radio input[type="radio"] ~ .radio-label:empty:before {
      margin-right: 5em;
    }
    
    .radio-label {
        line-height: 1rem;
    }
     <div>
        <label> Radio buttons </label>
        <div class="col-md-3 radio">
          <label class="radio-inline">
            <input type="radio" value="'NONE'" name="feature1" checked="checked" disabled="disabled"/>
            <span class="radio-label"> OPT I </span>
          </label>
        </div>
         <div class="col-md-3 radio">
          <label class="radio-inline">
            <input type="radio" value="'NONE'" name="feature1" disabled="disabled"/>
            <span class="radio-label"> OPT II </span>
          </label>
        </div>
         <div class="col-md-3 radio">
          <label class="radio-inline">
            <input type="radio" value="'NONE'" name="feature1" disabled="disabled"/>
            <span class="radio-label"> OPT III </span>
          </label>
        </div>
        
      </div>
    
    </body>
    </html>

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

Ensure consistency in CSS3 background color transitions

There are multiple elements on the webpage with background transitions that change from one color to another: @-moz-keyframes backgroundTransition /* Firefox */ { 0% {background-color:#ff7b7b;} 33% {background-color:#7fceff;} 66% {backgr ...

Tips on positioning a div based on the screen dimensions

In my table, there is an icon that reveals a chart as a popup when hovered over. This div is where the chart is displayed: <div id="chart-outer" style="@style" class="popup-chart close"> <h2 id="charttitle&q ...

A step-by-step guide on implementing an if-else statement to remove an item from Angular

I am currently working on implementing a feature that allows me to delete an item only if the quantity of that item is 0. If the quantity is not equal to 0, I need to prevent deletion and send an error message back to the front end. Below is my implementa ...

Utilize flexbox to make two elements on the same line

Is it feasible to have two elements on the same line when aligning a series of elements with flexbox? Consider this scenario: .outer { display: flex; flex-direction: column; margin-left: auto; margin-right: auto; width: 50px; } .outer .inner ...

What is the best way to position a rectangle on top of a div that has been rendered using

I recently started using a waveform display/play library known as wavesurfer. Within the code snippet below, I have integrated two wavesurfer objects that are displayed and positioned inside div elements of type "container". My goal is to position my own ...

Is there a valid substitute for using hot links with images?

Currently, I am instructing a group of individuals on the intricacies of web development with a specific focus on AngularJS. As part of an exercise that I designed for them, they are required to fetch data from the freely accessible pokeapi.co. One interes ...

What is the method for reverting style properties back to their CSS defaults using Javascript?

The php-generated page contains multiple elements structured like this: <td class="defaultTDStyle" style="color:userDefinedCustomColor" id="myTDId"></td> There is a default style in place with additional styles ap ...

Leveraging jQuery to manipulate an SVG file

jQuery is designed to work within HTML pages that contain JavaScript code. While SVG and HTML both use the same DOM Level 2, SVG is XML-based and employs ECMAScript. What potential issues could arise from utilizing jQuery with SVG? Is it more advisable t ...

The proper approach is using CSS for linking pseudo-classes

Look what I stumbled upon: Important: Remember, a:hover MUST be placed after a:link and a:visited in the CSS code to work properly!! Remember: Place a:active after a:hover for it to have an effect in the CSS code!! Note: Pseudo-class names are not case- ...

Is it possible to nest a <div> element inside a table in HTML code?

I am facing a requirement where I need the table rows inside a table, excluding the head row, to be scrollable. I attempted the following code, but it did not produce the desired outcome: <table id="applicantList1" border="1" align="left"> &l ...

Alignment of containers on the same level in a horizontal direction

Looking to achieve horizontal alignment of div containers. The container on the left (with a blue border) may have a fixed height. The other two containers (with red borders) should be aligned horizontally to the left blue container regardless of its heigh ...

There seems to be a malfunction with the hide and reset features, as they are

I have encountered an issue while working on hiding a series in Google Charts when clicked on the legend. The problem arises when an extra column is added to display tooltips on the bars, causing the functionality to break. Please check out the demos below ...

What is preventing me from directly taking from Codepen?

Looking to experiment with a different landing page? Take inspiration from this example. Here's the HTML snippet, for more details check out the full code on Codepen. <link href='http://fonts.googleapis.com/css?family=Lobster' rel=&apos ...

Issue with MUI data grid not resizing properly within a grid container: The dimensions of the MUI data grid are not adjusting as anticipated

In my setup, I have a main grid <div> container that contains two child elements. One is the MUI <DataGrid />, and the other is a simple <div>: Here's how it looks in JSX (React): <div className="container"> <Da ...

Efficiently Displaying Multiple HTML Elements in React Native WebView

I am currently working on developing an Epub reader in React Native and facing a challenge. I need to find a way to efficiently transfer multiple html content files from the Epub container to the webview in order to achieve seamless pagination. ...

Jquery function for determining height across multiple browsers

I am currently facing an issue with setting the height of table cells in my project. While everything works smoothly on most browsers, Firefox seems to add borders to the overall height which is causing inconsistency across different browsers. If anyone k ...

Use Vue.js to shorten the number of decimal places and include commas in numerical values

How can I best parse a long number retrieved from a JSON using VueJS within a for loop? The JSON data is used in a v-for prop to create Li elements for a side navigation. I attempted to use vue-numeric without success since the project does not utilize ECM ...

Having trouble executing javascript with Ext.Ajax in Sencha-Touch2?

Currently, I am utilizing htmlPanel.js in Sencha-Touch as discussed in the Forum here to exhibit local HTML content. Even though I can load the HTML content with standard HTML tags, I'm facing issues with loading JavaScript. Here's the snippet o ...

Using TypeScript, pass an image as a prop in a Styled Component

I am facing an issue with the code below that is supposed to display the "NoBillsLaptopPNG.src" image on the screen, but for some reason, the image is not showing up. The images are being imported correctly, so I'm unsure why the image is not appeari ...

Retrieve information stored in a JSON data field within the results of an npm

How can I properly access the value of DepDateTime from the first object? Here is my current attempt: const nodeSkanetrafiken = require('node-skanetrafiken'); const from = { name: 'Bjärred centrum', id: 62025, type: 0 }; const to = ...