Conflicting with other label tags, the custom radio button is causing issues

I've implemented custom radio buttons using CSS that hide the original ones and utilize the LABEL tag to display images instead. However, I'm facing an issue where it conflicts with labels on textboxes as well.

Since I have a large number of radio buttons, adding a class to each one isn't ideal. Is there a way to modify the CSS so it only affects the LABEL tags for the checkboxes/radio buttons?

Alternatively, I could consider removing the labels from the textboxes since they don't require clickability, but I'd like to explore other solutions too.

JS FIDDLE

HTML:

<input type="radio" name="question10" id="radio10c" value="radio" />
<label class="black" for="radio10c">Mostly</label>
<br/>
<input type="text">
<label>Text box label with repeated pattern of radio button on the background</label>

CSS:

input[type=radio], input[type=checkbox] {
    display: none;
}
input[type=radio]+ label, input[type=checkbox] + label {
    padding-left: 35px;
    padding-top: 2px;
    height: 30px;
    display: inline-block;
    line-height: 30px;
    background-repeat: no-repeat;
    background-position: 0 0;
    font-size: 12px;
    vertical-align: middle;
    cursor: pointer;
}
input[type=radio]:checked + label, input[type=checkbox]:checked + label {
    background-position: 0 -30px;
}
label {
    padding-bottom:2px;
    background-image: url(http://cis.kitoit.com/layouts/images/radio.png);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

Answer №1

Could you kindly update this CSS? Is this the modification you were looking for?

input[type=radio], input[type=checkbox] {
    display: none;
}
input[type=radio]+ label, input[type=checkbox] + label {
    padding-left: 35px;
    padding-top: 2px;
    height: 30px;
    display: inline-block;
    line-height: 30px;
    background-repeat: no-repeat;
    background-position: 0 0;
    font-size: 12px;
    vertical-align: middle;
    cursor: pointer;
}
input[type=radio]:checked + label, input[type=checkbox]:checked + label {
    background-position: 0 -30px;
}
input[type=radio] + label {
    padding-bottom:2px;
    background-image: url(http://cis.kitoit.com/layouts/images/radio.png);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

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

Encountering a 404 error while trying to use the autolinker

I have been struggling with this issue for the past day and can't seem to solve it on my own. Essentially, I am attempting to use Autolinker.js to automatically convert URLs into clickable hyperlinks in my chat application. However, every time I try ...

The hover action in the Jquery Accordion does not activate when a section has been opened before

I'm facing a problem with my jQuery accordion menu. After opening and closing a section, the ':hover' effect stops working only for that specific section. However, it continues to work for other sections that haven't been clicked yet. ...

What are the steps for specifically editing the mobile version of a website?

I am currently gaining experience by working on a website, but I am facing some challenges in making changes specifically for the mobile version. Here is an example: <h1 class="intro-header__title"> <span>Are you ready to</span> Expa ...

two adjacent elements filling the entire height of the window at 100% dimensions

Is there a way to place two elements side by side, with one of them (the textarea) always being 100% height of the window? I've looked at similar questions here but can't figure out how to make it work. Can you help me with this? html: <div ...

Best practices for formatting JSON in PHP

Currently, I am utilizing PHP to gather inputs from an HTML form and insert them into a JSON file using the following code: $file = ('inputs'); $array = array( 'First Name' => $firstname, 'Last Name' = ...

Is the .html page cached and accessible offline if not included in the service-worker.js file?

During the development of my PWA, I encountered an unexpected behavior with caching. I included a test .html page for testing purposes that was not supposed to be cached in the sw.js folder. Additionally, I added some external links for testing. However, w ...

Tips for creating a left-floating element with a horizontal scrolling area

I am trying to make this outer <div> scroll only in the x-axis, but it doesn't seem to be working properly. .wrapper { width: 98%; height: 320px; padding-left:1%; padding-right:1%; white-space: nowrap; overflow-y: hidden; over ...

I am encountering an issue with Php where it is not accurately retrieving the data from my form

My current approach involves using Ajax to transfer the form values to a PHP file for insertion into a database. Depending on which button is clicked, a specific URL - in this case, insert_shirt.php - should be executed. However, I'm encountering an i ...

Steps for adding a cover over an image (not utilizing clip-path, but the reverse approach)

I am currently exploring how to create a div with a mask that allows me to see through it to reveal a background image. Most tutorials I find discuss clip-paths, but what I am seeking is the opposite of this concept. Clip-paths typically display what is in ...

Why is the Django image URL redirecting to an HTML template instead of the media file?

I created a Django application with a template that includes an image. However, I encountered an issue where the server is attempting to display the image using the redirect link from the HTML template instead of retrieving it from the media file. For ins ...

Use the powerful $.post() method to transfer an image to another page seamlessly

I have two pages, the first page contains a form where users can enter information such as name and mobile number. Additionally, they can upload an image. I would like to use jQuery to access the uploaded image and send it to another page using the $.post( ...

Creating an animated diagonal line using TweenMax/EaselJS can add a dynamic element to your designs

I am looking to create a constellation by connecting stars with animated lines. I have attached an image to show the desired end result. The stars and lines are generated using HTML5 canvas and easelJS. Below is the code snippet I have been working on, wh ...

Align boxes in the center within a DIV container

Here is the box design that I have created: https://i.sstatic.net/3rtcn.jpg The green color boxes are generated dynamically inside a "col-md-10" div. If there are less than 3 boxes in the second row, I would like to center align them. For example, in thi ...

Having difficulty changing the value of a Select element in AngularJS

Struggling to update the select value from AngularJs. Check out my code below: <select ng-model="family.grade" > <option ng-repeat="option in options" value='{{option.id}}'>{{option.text}}</option> </s ...

A guide on grouping an entire CSS file under one class umbrella

Is there a way to encapsulate a large number of CSS declarations so they only apply when the parent has a specified class? div { color: #ffffff; } ... a { color: #000000; } Can it be structured like this, with a parent class containing all the CSS r ...

using jQuery to disable textarea input

I have this HTML code and I am using jQuery: <div><textarea style="height: 150px; width: 250px" name="myName" id="myId" class="text ui-widget-content ui-corner-all" > </textarea></div> Currently, I validate this field after the su ...

The sourcemap generated by gulp is not functioning as expected

Custom Styling custom-styles.less @import "theme.less"; @import "layout.less"; theme.less body { background:blue; } layout.less body { font-family: Arial, sans-serif; } Build Process - Gulpfile.js var gulp = require('gulp'); var less = re ...

The synergy between HTML and JavaScript: A beginner's guide to frontend coding

I have primarily focused on server-side development of enterprise applications (Java EE, Spring framework). However, I am now exploring client-side technologies for better understanding (not necessarily to become an expert). I have studied HTML and CSS th ...

D3 Tree and Leaflet Map Unintentional Disruption

I have set up a Leaflet Map in one div and a collapsible tree using d3 in another div (based on this Fiddle): https://i.sstatic.net/zAC2m.png The Leaflet Map (located in the right div) loads a GeoJSON, while the D3 tree (in the left div) loads correspondi ...

The opacity of gmap-window cannot be defined because the property is undefined

Experiencing the following issue: Cannot set property 'opacity' of undefined Here is the HTML and JavaScript code snippet: <ui-gmap-window show="map.infoWindow.show" coords="map.infoWindow.center" options="map.infoWindow.options"></ui- ...