After applying CSS, I am unable to click on the radio buttons

Even after selecting the other two, it still defaults to the first one.
Here is my code:

input[type=radio] {
            display:none;
}


    input[type=radio] + label:before {
            content: "";  
            display: inline-block;  
            width: 35px;  
            height: 35px;  
            vertical-align:middle;
            margin-right: 8px;  
            background-color: #DFF0EF;  
            box-shadow: inset 0px 2px 2px rgba(0, 0, 0, .3);
            border-radius: 4px;  
        }

    input[type=radio]:checked + label:before {
            content:"\2714";
            color:white;
            background-color: #34E098; 
            font-size:1.5em;
            text-align:center;
            line-height:34px;
            text-shadow:0px 0px 3px #eee;

        }


Check out my buttons on CodePen: https://codepen.io/coderguyinthehouse/pen/VjbdLd

Answer №1

It is important for your IDs to be unique, along with the corresponding labels' for attribute.

For example:

<input type="radio" id="sizeselected1" name="downloadsize" value="KB">
<label for="sizeselected1">1</label>

input[type=radio] {
            display:none;
}

input[type=radio] + label:before {
        content: "";  
        display: inline-block;  
        width: 35px;  
        height: 35px;  
        vertical-align:middle;
        margin-right: 8px;  
        background-color: #DFF0EF;  
        box-shadow: inset 0px 2px 2px rgba(0, 0, 0, .3);
        border-radius: 4px;  
    }

input[type=radio]:checked + label:before {
        content:"\2714";
        color:white;
        background-color: #34E098; 
        font-size:1.5em;
        text-align:center;
        line-height:34px;
        text-shadow:0px 0px 3px #eee;
       
    }
<form class="sizeselect" id="sizeselect" name="sizeselect">
  <input type="radio" id="sizeselected1" name="downloadsize" value="KB"><label for="sizeselected1">1</label>
  <input type="radio" id="sizeselected2" name="downloadsize" value="MB"><label for="sizeselected2">2</label>
  <input type="radio" id="sizeselected3" name="downloadsize" value="GB"><label for="sizeselected3">3</label>
</form>

<form class="speedselect" id="speedselect" name="speedselect">
  <input type="radio" id="speedselected1" name="downloadspeed" value="Kbps"><label for="speedselected1">11</label>
  <input type="radio" id="speedselected2" name="downloadspeed" value="Mbps"> <label for="speedselected2">12</label>
  <input type="radio" id="speedselected3" name="downloadspeed" value="Gbps"> <label for="speedselected3">13</label>
</form>

Answer №2

Avoid using the same ID's for different elements.

<form class="sizeselect" id="sizespecific" name="sizespecific">
<input type="radio" id="sizeoption1" name="downloadsize" value="KB"
<label for="sizeoption1">1</label>
 <input type="radio" id="sizeoption2" name="downloadsize" value="MB"
<label for="sizeoption2">2</label>
<input type="radio" id="sizeoption3" name="downloadsize" value="GB"
<label for="sizeoption3">3</label>
</form>

Remember to update IDs in other forms as well.

Answer №3

It's important to assign a unique identifier to each input element

<form class="sizeselect" name="sizeselect">
  <input type="radio" id="sizeselected1" name="downloadsize" value="KB"><label for="sizeselected1">1</label>
  <input type="radio" id="sizeselected2" name="downloadsize" value="MB"><label for="sizeselected2">2</label>
  <input type="radio" id="sizeselected3" name="downloadsize" value="GB"><label for="sizeselected3">3</label>
</form>

<form class="speedselect" name="speedselect">
  <input type="radio" id="speedselected11" name="downloadspeed" value="Kbps"><label for="speedselected11">11</label>
  <input type="radio" id="speedselected12" name="downloadspeed" value="Mbps"> <label for="speedselected12">12</label>
  <input type="radio" id="speedselected13" name="downloadspeed" value="Gbps"> <label for="speedselected13">13</label>
</form>

Answer №4

If you're utilizing custom checkboxes, the checked state will activate when you click on the label. However, all of the labels are associated with the same input (sizeselected). To fix this issue, simply change the IDs for each input and everything should function as expected!

    <form class="sizeselect" id="sizeselect" name="sizeselect">
      <input type="radio" id="sizeselected" name="downloadsize" value="KB">
      <label for="sizeselected">1</label>
      <input type="radio" id="sizeselected2" name="downloadsize" value="MB">        
      <label for="sizeselected2">2</label>
      <input type="radio" id="sizeselected3" name="downloadsize" value="GB">
      <label for="sizeselected3">3</label>
    </form>

https://codepen.io/will0220/pen/KrmZqr

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

Why is the Slick Slider displaying previous and next buttons instead of icons?

I'm currently working on creating a slider using the slick slider. Everything seems to be functioning properly, but instead of displaying arrows on the sides, it's showing Previous and Next buttons stacked vertically on the left side. It appears ...

Bootstrap 4 Nav Table of Contents with Expand and Collapse Feature

Currently, I am encountering an issue with implementing a button to expand and collapse a "table of contents" in Bootstrap 4. The code I have so far can be viewed here: https://codepen.io/nht910/pen/RwwwyKB Code Snippet: <div class="main-wrapper col- ...

Can AngularJS Filters be used to convert a number into a string, but not the other way around?

After researching Angular JS filters, I discovered that the number filter is used to format a number as a string. However, there doesn't seem to be a built-in filter for converting a string to a number. In an attempt to solve this issue, here is so ...

Tips for addressing the issue of button flickering due to CSS transitions

Is there a solution to prevent flickering without compromising the intended design? The issue arises when hovering over a moving or animated element and accidentally un-hovering because it moves beneath the cursor. <!DOCTYPE html> <html> &l ...

Is it possible to make the mat-menu-item the same size as the mat-menu button in Angular Material v.12?

How can I ensure that the mat-menu-item button is the same size as the mat-menu itself? For example, click here <div class="container d-block d-md-none"> <div class="row"> <div class="col d-flex justify-content-cent ...

Ensure that the Popover vanishes upon scrolling the page - Material UI (MUI) v5 compatibility with React

When implementing the MUI v5 standard pattern for displaying a popover upon hovering over another element, everything works smoothly except for one scenario: If you hover over the element And without moving the mouse, use the scroll wheel to scroll throug ...

Desktop media queries are functioning properly, yet experiencing issues on mobile devices

I've come across this same question multiple times, but the solutions I've found so far haven't been helpful. My media queries are working perfectly on desktop, but they don't seem to take effect on three different android devices. It&a ...

I am facing an issue with grabbing text using simple HTML DOM in PHP with cURL

I have implemented the following code in my script to extract a specific part of the source code that I require, but I encountered this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting ')' in /home/cyberhos/pub ...

Developing a downloadable PDF version of an online platform

For weeks now, I have been tirelessly searching for a solution to a problem that has stumped me once before. The Challenge: My company created a sophisticated web-based data analytics suite for a major beverage distributor. Our client is now requesting a ...

The height of the input element is greater than the size of the font

I am facing an issue with an input element that has a height 2px higher than what I expected. Here is the relevant CSS: .input { font-size: 16px; padding: 15px; border: 1px solid black; border-radius: 3px; width: 400px; } <input class=" ...

`Using a Video in a JQuery Carousel`

Currently in the early stages of developing a JQuery Slider that will kick off with a video, transitioning into slideshow mode once the video concludes. My goal is to ensure compatibility with IE9 and lower, as well as iPhone devices, necessitating options ...

Dividing an AngularJS module across multiple iFrames on a single webpage

Currently, I am working on a web application that consists of 1 module, 5 pages, and 5 controllers. Each HTML page declares the same ng-app. These pages are loaded within widgets on a web portal, meaning each page is loaded within an iFrame in the portal. ...

I'm encountering a Python Selenium error related to the timing of webpage loading

# Specifying the path to the chromedriver program service = Service('C:\Program Files (x86)\Google\chromedriver.exe') service.start() # Opening a remote connection with robinhood website using the driver driver = webdriver.Remote( ...

PHP error: Index not defined

One challenge I’m encountering is with a dating site form that includes the following categories: firstname,lastname,username,password,email,mysex,yoursex,relationship,date of birth, and country I've completed the PHP code to send information to a ...

Unable to Toggle Bootstrap 5 Dropdown

Take a look at my code below. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewpor ...

Enable the feature for users to upload images to a specific folder within the Chrome extension without the need for

I need to implement a feature in my Chrome extension that allows users to upload images directly to a specific folder named "upload" without needing a submit button. <form action="/upload"> <input type="file" name="myimages" accept="image/*"> ...

Minimize the space between flex items

I'm currently working with a <div> container styled as flex using the following CSS properties: .icon-container { padding: 3px; padding-top: 15px; padding-bottom: 15px; display: flex; flex-direction: column; align-content ...

Having trouble getting the .toggle() function with classList to work on one element, despite working fine on others

I've been struggling to apply a class to an HTML element when I click on another element of the page. Despite numerous attempts, it just doesn't seem to work for me. Let's take a look at my code: HTML Code: <div class="container&qu ...

Utilizing jQuery to extract the `h1` element from a dynamically loaded external page within the

I am facing a challenge in selecting an h1 element from a remote page that I have loaded into $(data). Despite several attempts, I am struggling to write the correct code. When I use this code: console.log($(data)); The output is as follows: [text, meta ...

The popover seems to be failing to appear

I am struggling to get a popover to appear when clicking on an appended href element dynamically. Here are the code snippets I have tried: <div id="myPopoverContent"> ...stuff... </div> <div id="div3" style= "width:200px;height:200px;" ...