Why does the checked pseudo class seem to be unresponsive?

I have been attempting to customize the appearance of radio buttons, but I am encountering issues with the checked pseudo-class. Interestingly, the hover effect is working perfectly. Although this is just a small section of a larger form, I am focusing on getting this part right before implementing it elsewhere. I believe I have included all the necessary code, but I can provide more if required. Thank you!

 <div class="form-group__radio-item">
   <label for="yes" class=form-group__radio-label>Yes
      <input name="data-radios" class="form-group__radio-input" id="yes" type="radio">
      <span class="form-group__radio-button"></span>
   </label>
 </div>
 <div class="form-group__radio-item">
   <label for="no" class=form-group__radio-label>No
      <input type="radio" name="data-radios" class="form-group__radio-input" id="no">
       <span class="form-group__radio-button"></span>
   </label>
 </div>
&__radio-group {
      display: flex;
      flex-direction: row;
      justify-content: space-around;
    }

    &__radio-label {
      font-family: $theme;
      position: relative;
      font-weight: 400;
      font-size: 0.875rem;
      color: $colorLightGray;
      margin-right: 2px;
      padding-bottom: 1rem;
      user-select: none;
      }

    &__radio-box {
      margin: 0 1rem 0 1rem;
    }

    &__radio-item {
      padding-bottom: 0.5rem;
    }

    &__radio-input {
      margin-right: 0.5rem;
      margin-bottom: 1rem;
    }

    &__radio-input:checked + &__radio-button{
        background-color: blue;
    }

    &__radio-input:hover + &__radio-button {
      background-color: green;
  }

    &__radio-button {
      position: absolute;
      display: inline-block;
      border: 2px solid red;
      top: 0rem;
      right: 3rem;
      height: 15px;
      width: 15px;
      border-radius: 50%;

      &::after {
        content: "";
        display: block;
        height: 1.3rem;
        width: 1.3rem;
        border-radius: 50%;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background-color: red;
        opacity: 0;
        transition: opacity .2s;
    }

      &:hover{
        background-color: yellowgreen;
      }
    }

Answer №1

To display your custom input, I've included padding-left in the __radio-label class, set z-index and opacity in __radio-input to hide the basic input, and adjusted the alignment of custom inputs by changing the right to left for __radio-button.

.form-group {
  &__radio-label {
    position: relative;
    font-weight: 400;
    font-size: 0.875rem;
    padding-left: 1.5rem;
    padding-bottom: 1rem;
    user-select: none;
  }

  &__radio-box {
    margin: 0 1rem 0 1rem;
  }

  &__radio-item {
    padding-bottom: 0.5rem;
  }

  &__radio-input {
    z-index: -1;
    opacity: 0;
  }

  &__radio-input:checked + &__radio-button{
    background-color: blue;
  }

  &__radio-input:hover + &__radio-button {
    background-color: green;
  }

  &__radio-button {
    position: absolute;
    display: inline-block;
    border: 2px solid red;
    top: 0rem;
    left: 0;
    height: 15px;
    width: 15px;
    border-radius: 50%;

    &::after {
      content: "";
      display: block;
      height: 1.3rem;
      width: 1.3rem;
      border-radius: 50%;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      background-color: red;
      opacity: 0;
      transition: opacity .2s;
    }

    &:hover{
      background-color: yellowgreen;
    }
  }
}

I trust this resolves the issue for you

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

The styles from the Next.js module are being overridden by the styles from mui/material

Currently, I am working with next.js and using scss modules for styling. However, I have encountered an interesting issue while using mui/material components. During development (npm run dev), everything functions as expected. The problem arises when I swi ...

Remove the option to delete without making any changes to the flash file

Utilizing the DataTable javascript tool to export a grid, I have obtained the following HTML generated code: <div class="DTTT_container"> <a class="DTTT_button DTTT_button_copy" id="ToolTables_example_0" tabindex="0" aria-controls="e ...

Retrieving content from a div element

I am using Beautiful Soup to extract a list from HTML attributes. g_info = soup.find_all("div", {"id":"details_readonly"}) print g_info ## this prints out all the contents of the div tag. y = re.compile(r'B00(.{7})',g_info) print y The extrac ...

Using the arrow keys, I must adjust the border sides

I am looking to switch between different sides of borders by using the arrow keys $(function(){ $(document).keydown(function(e){ switch(e.which){ case 38:$("#sh").css("border-top-color", "#fff"); //arrow up break; ...

The rectangular shape extending beyond the boundaries of the canvas

I'm currently working on creating a rectangle within a canvas element. I've set the width of the div to match the width of the rectangle, but unfortunately, the rectangle is extending beyond the left side of the canvas container. My goal is to co ...

Creating a custom Chrome extension with the ability to modify the pop-up window instead of the web page

Is there a way to modify the content inside my extension's pop-up without affecting the web page being viewed by the user? Also, how can I ensure that my dropdown list functions correctly? I have two dropdown lists where selecting an option from the ...

JavaScript for Altering Viewport/Screen Width

Lately, I've been experimenting with creating a responsive button for our new website. The goal is to adjust the body width to 460px, simulating how our site would appear on mobile devices. While researching, I came across a technique that utilizes if ...

iOS Safari is displaying the keyboard with a comma instead of a period

Is there a way to display a comma instead of a period on the iOS keyboard in Safari? Upon tapping on the input field, users are presented with a keyboard featuring a period. https://i.sstatic.net/nMFCg.png ...

Is it feasible to programmatically click a div button in C# using WebBrowser?

Exploring the capabilities of WebBrowser in C#, I came across a website that features a button without an ID, but rather nested within a div element. <div class="pc-image-info-box-button-btn-text pc-cursor"><i class="fa fa-heart" aria-hidden="tru ...

The text remains separate from the image

I am attempting to arrange text around an image, with the image on the left and text on the right. Despite using the latest version of Bootstrap and assigning col-3 and col-9 to both sides, I am facing issues. The text does not move below the image when it ...

Align a button within an input field to be in line with a stacked label in

I'm currently facing some issues with Ionic because it's not placing my button where I want it to be: https://i.stack.imgur.com/qtUQJ.png My goal is to have the button on the same line as the input, similar to the clear-button. This is the cod ...

How can I retrieve the input value on the current page using PHP?

Hey there, so I'm pretty new to PHP and I have a question. Is it possible to retrieve the input value from an existing input field on a page using PHP when the page loads, and then assign that value to a variable? For instance, let's say I have ...

Transforming the appearance of the menu element in Vue using transitions

In my Vue app, I have this SCSS code that I'm using to create a smooth transition effect from the left for a menu when the isVisible property is set to true. However, I am encountering an issue where the transition defined does not apply and the menu ...

Saving Data in an Angular Material Table: A How-to Guide

I have a basic angular material table and I am looking for a way to save the data displayed in each row when a button is clicked. Is it possible to save each row of data as an object and push it to an array? If so, how can I achieve this? <div class=& ...

Difficulty resizing background image on iPhone

I am having an issue with the background image resizing correctly on my website, specifically on iPhone (I have not yet checked iPad). You can view the site here. The dimensions of the image are 1393 x 1098 pixels. Below is the CSS code I am currently us ...

In order to format my text, I must locate a specific character and encompass the text following it with HTML tags

When working with a list generated in Jekyll, I came across the need to emphasize certain words using strong tags. My solution was to incorporate a delimiter into the process. <li>100g of |sugar</li> This would transform into: <li>100g ...

Selected a radio button within a jQuery UI dialog box

After using jquery-ui, I was able to create a simple dialog window. It looks like this: <div id="dialog-form" title="Add Attribute Category"> <input type="radio" id="priceable" name="price" value="true" checked="checked"/> Priceable &l ...

Can anyone recommend a user-friendly JavaScript dialog box compatible with jQuery that is mobile-responsive?

Mobile browsers. Using Jquery dialog alert box. Avoiding the use of alert() due to its unattractive appearance in web browsers. In the process of creating a website for both mobile and web platforms, seeking a dialog box that is compatible with both. ...

What is the best way to ensure that my text always aligns perfectly to the end of the line?

I've been struggling to create a column layout where the text perfectly aligns with the end of the line, but so far, I haven't had any success. Despite my efforts to find a solution online, I have come up empty-handed. What I'm aiming for i ...

Burger menu floating above container block element

I have set up a bootstrap container with the following styling: .container { margin-top: 12em; font-family: 'Amatic SC', cursive; border-bottom: 1px solid; border-color: #800000; } The purpose behind this is to have my navigatio ...