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

Issue with CSS color gradient transparency

I've successfully implemented a gradient that transitions from transparent to white by using the following CSS code: linear-gradient(to right, transparent, white) If you want to see it in action, click on this link: http://jsfiddle.net/fs8gpha2/ Al ...

The .remove() method is ineffective when used within an Ajax success function

I am facing an issue with removing HTML divs generated using jinja2 as shown below: {% for student in students %} <div class="item" id="{{ student.id }}_div"> <div class="right floated content"> <div class="negative ui button compa ...

Strangely peculiar glitch found in browsers built on the Chromium platform

During a school assignment, I'm attempting to adjust the width of a button using Javascript. Below is my code: const button = document.querySelector("button"); button.addEventListener("click", () => { console.log(button.offsetWidth); butto ...

When the mouse leaves, the background image will revert back to its original setting

https://i.stack.imgur.com/Ojd0Q.pngI need assistance in reverting a div's background image back to its default state using the onmouseleave method. Below is the HTML and JS code I have been working on: <script type="text/javascript"> functi ...

How to activate the menu in AngularJS

Within my application, I have a header that contains various menu items. These menu items are fetched from a service and displayed in the header. When hovering over the main list, the submenus appear. My goal is to highlight the parent item as active when ...

Is the first child component of Material UI Stack not properly aligned?

Is there a CSS issue that needs fixing? I am working on creating a vertical list of checkboxes with labels using the <Stack /> component from Material UI. I have tried implementing this in the sandbox provided (check out demo.tsx): https://codesandb ...

Get rid of any fonts that are causing rendering delays on amp pages

Encountering issues with Google Lighthouse and AMP Pages I have attempted various solutions but none seem to be working <link rel="preload" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,600,700,900&display=swap ...

Adjust the color of the glyphicon icon within a date and time picker dropdown component

I decided to implement the bootstrap datetimepicker using this gem and utilized the following HTML code: <div id="custom-dates" style=" clear:both;"> <div class="container"> <div class="row"> <div class='col-md-3 col-xs-3' ...

Is it possible to showcase dates within input text boxes prior to POSTing the form?

I am currently working on a form that posts to a PHP script by selecting a date range. For a better understanding, you can check out my visual representation here. Before the data is posted, I would like to display the selected dates in empty boxes or inpu ...

Anime.js: Grid layout causing issues with displaying simple text animations

I'm attempting to create a text animation within a grid layout using the anime.js library, but unfortunately, the animation isn't displaying. The project consists of just one HTML file. The JavaScript code: <script> import anime from &ap ...

Looking to prevent horizontal scrolling on smartphones in an HTML webview - how can I do this?

Currently, I am dealing with a webview and encountering some peculiar behavior. The overflow-x property is set to hidden, which works perfectly on browsers. However, when accessed on a mobile device, the overflow seems to be ignored completely. Here is t ...

Having difficulty displaying this code accurately on Google Chrome

I managed to create a hover effect over a series of images that displays additional information when hovered over. Below is the code I used: HTML <ul class="photo-grid"> <li> <a href="https://www.abglobal.com/" target="_blank"& ...

The Calibri Light font is not supported by Chrome version 37

Yesterday my website was working fine, but today when I checked it, some strange issues appeared. The Calibri Light font that I used extensively has been replaced with the default font, and the width of input fields has changed. How can I resolve this issu ...

HTML5 canvas processing causing web worker to run out of memory

Within the Main thread: The source image array is obtained using the getImageData method. It is represented as a uint8ClampedArray to store the image data. Below is the code executed in a web worker: (This operation generates a high-resolution image, but ...

Is there a way to synchronize breakpoint values across different media queries?

Currently utilizing Next.js version 9.53. Utilizing the built-in CSS module support provided by Next.js without the use of CSS pre-processors (less, sass, etc.) or CSS-in-JS (styled-components, etc.). Presently, my approach involves writing CSS in a mobi ...

"Creating a cohesive design: Using CSS to ensure the navigation background complements

I am working on a project with a horizontal navbar that I want to stay fixed while scrolling. The main window has different colored divs as you scroll down, and I would like the navbar to match the image of the main div while scrolling, creating a looping ...

A webpage specified with 'charset=iso-8859-1' accompanied by <!DOCTYPE HTML> is triggering a cautionary alert

After running the W3C validator on an HTML document, I discovered that using the following meta tag: <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> in conjunction with: <!DOCTYPE HTML> results in ...

Storing persistent JSON data in a mobile app built with HTML5 involves utilizing the local storage capabilities of the

I am currently working on a mobile app using PhoneGap that is based on HTML technology. When the app is opened for the first time, my goal is to have it download a zip file that includes a JSON file and media files such as images or audio. Once the zip f ...

Use the given URL to set the background image

Having trouble setting a background image for an <a> tag. The image link is set in the background-image:url property, but the image isn't showing up as the background. Here's my code, what could be the issue? <a href="#" data-to ...

Why don't media queries take effect

After thoroughly reading all the @media topics on this site, it appears that the code should be functioning correctly. body { background-color: yellow; } @media screen and (min-width: 1080px;) and (max-width: 2000px;) { body { backgrou ...