:selected element malfunctioning

I've been struggling to make the following code work:

html

<div class = "col-md-4 video text-center wrapper-q1">
     <p class = "no-padding">
        <input class="question1" id = "vraag1" type="radio" name="q1" value="Moon"> <br />
        <label class = "pointer" for = "vraag1">Text</label>
     </p>
</div>

css

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

label:before {
    content: "";
    display: block;
    width: 33px;
    height:33px;
    margin:0 auto;
    background-image: url("../img/radio-btn.png");
}

input[type=radio]:checked + label {
    content: "";
    background-image: url("../img/radio-btn-checked.png");
    font-size: 30px;
    text-align: center;
    line-height: 18px;
}

While the radio button displays, I'm having trouble getting it to switch to the "checked" image when clicked.

Any assistance or guidance would be greatly appreciated!

Answer №1

You forgot to include the :before pseudo-element

CSS:

input[type=radio]:checked ~ label:before {
    content: "";
    background-image: url("../img/radio-btn-checked.png");
    font-size: 30px;
    text-align: center;
    line-height: 18px;
}

Answer №2

To implement the functionality, try using

input[type=radio]:checked ~ label

As an alternative to the outdated method of

input[type=radio]:checked + label

This updated approach should meet your requirements.

Feel free to check out the demonstration on Fiddle

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

Monitoring changes to a SCSS file

I'm feeling completely baffled. I've put in my best effort to resolve this issue. The problem lies with my SCSS file and its watcher that doesn't appear to be functioning properly. A regular CSS file is not being generated at all. Here&apos ...

The visual symbol is not being shown on the selection box in Mozilla Firefox

I've encountered an issue with a checkbox I created to display a + and - for expand and collapse functionality. HTML Code: <input type=checkbox class="ins" ng-model=show ng-class='{open:show}'><b>Show</b> CSS code: .ins ...

Position elements flush to the left and right

Is it possible to align the text in divs so that it perfectly lines up along the edges? .name { margin: 0 0 5px 10px; font-weight: bold; font-size: 14px; } .row { margin: 0 0 5px 10px; width: 500px; justify-content: space-between; } < ...

Ways to compel links to open in Internet Explorer

In one of my chatbot messages, I have included a link to a web app that is only compatible with Internet Explorer. My chatbot runs on Google Chrome, so when the user clicks on the link, it opens in a new Chrome tab instead of in IE, where it should open f ...

Show or hide a div based on the visibility of another div in Angular using *ngIf

Looking for a way to dynamically display images based on the visibility of another image? Consider the code snippet below: <div *ngFor="let badge of user.progress.unlockedBadges"> <img id="{{i}}_unlockedImage" *ngIf="badge == achievemen ...

Is there a method to uncover the code that controls the display of a <div> element?

As a fresh face at the company, I've been given the responsibility of developing a chart that is similar to one already present on their website. While I have the knowledge and skills to create it, I am struggling to locate the specific code where the ...

Finding the appropriate method to access a template variable reference in a designated row of an Angular Material table (Angular 7)

Currently, I am working on implementing a more intricate version of a behavior inspired by Angular Material's tutorials. In my simplified example, an Angular Material table is populated with data from a string array. The first column contains input fi ...

Achieving a centrally aligned flex container with left-aligned flex items

My goal is to center the flex items, but when they go onto a second line, I want item 5 (from image below) to be positioned under item 1 instead of centered in the parent container. https://i.sstatic.net/GhD1E.png Here's a sample of my current setup ...

Using Jquery to dynamically adjust the size of a div based on the width and height of the browser window

How can I dynamically change the height of a .test div based on the browser width and height? I want the value to update whenever the browser is resized. $(document).ready( function() { window.onresize = function(event) { resizeDiv(); ...

Navigating Checkbox in Active Choice Reactive Reference Parameter on Jenkins

I attempted to configure an active choice reactive reference parameter using the instructions outlined in this guide: Here is the code for the reactive reference parameter: service_tier_map = [ "web": [ ["service_name": "use ...

Ways to set a default image for an <img> tag

I am looking to set a default image to the img tag in case the user has not selected a profile picture for their account. Here is the current output: http://jsfiddle.net/LvsYc/2973/ Check out the default image here: This is the script being used: funct ...

Developing a placeholder directive with AngularJS

Are you looking to create a unique element in AngularJS to facilitate nested ng-repeats? Take a look at the example below: data.test = [{h:1, d:[11,12]}, {h:2, d:[21,22]}]; ---------------------- <custom ng-repeat="a in data.test"> <h3>{{a ...

CSS @page does not render content within @top-center, @bottom-right, and similar positions

Currently, I am working on generating a HTML file that is print-ready and have been using CSS @page for this purpose. However, I have encountered a major issue with displaying page numbers utilizing @bottom-right and other similar solutions. Could there be ...

Challenges arise with CSS alignment when adding d3.js charts to a webpage

I'm puzzled by the empty space that appears between the left column (highlighted in the image) and the header. This peculiar gap only seems to occur when the middle column is filled with a chart. I've scrutinized the code using Chrome Developer t ...

Ensure that all divs have the same height and padding when resizing

I have 3 divs nested within a parent div. My goal is to dynamically set the height of all the child divs to match the height of the div with the maximum height, even when the screen resizes due to responsiveness. Below is my HTML structure: <div class ...

What is the best way to create divs that can close and hide themselves when clicked from inside the div itself?

I have a situation in my code where clicking a link reveals a div, and then the same link must be clicked again to hide it. However, I want to modify this so that any link within the div can also hide it when clicked. I currently have eight divs set up lik ...

The height property in the CSS is causing the parent element to break and cannot be confined

Here is the HTML code that I am currently working with: <div id="div1"> <p id = "a"> <! -- content --> </p> <p id='b'> <! -- content --> </p> </div> Additionally, th ...

Determine if a draggable item is currently positioned over another element

In my body, there are several divs located: <div id="one"></div> <div id="two"></div> <div id="three"></div> All of these divs are draggable using jqueryUI: var $divs = $('#one, #two, #three'); $divs.draggab ...

How to update an array in Angular using ngModel and ngFor

I am attempting to display an array's values on a form and then allow for updating those same values in the array (using name="todos{{i}}" within the <input> tag does not work as it turns it into a string instead of an array). The curr ...

What is the best way to crop a page?

Running a React application, I am integrating a page from an external ASP.NET app. To achieve my goal of extracting only a section of the page rather than the entire content, I am unsure if it is feasible. Specifically, I aim to extract just the body of th ...