Distinguish between Label and Input fields

My label has a Input Radio with a unique background image applied to it. Take a look at the setup below:

I'm trying to adjust the positioning of "Ja" and "Nej" about 5-10 pixels to the left, but I'm struggling to find the right solution. Can someone offer assistance?

Here is the HTML:

<label id="labelradio1" for="Radio1">Ja
<input id="Radio1" type="radio" value="yes"></label>
<label id="labelradio2" for="Radio2">Nej
<input id="Radio2" type="radio" value="no"></label>

And here is the CSS:

#txtradiocall input[type='radio']{
    position:absolute;
    margin: -99999px;
}

#txtradiocall label{
    display: inline-block;
    cursor: pointer;
    width: 15px;
    height: 15px;
    margin: 4px;    
}

#txtradiocall #labelradio1 {
    background: url('http://www.xxxx.com/images/images/thumb_up_green-v2.png');
    background-repeat:no-repeat;
    cursor: pointer;
    width: 35px;
    height: 22px;
}

#txtradiocall #labelradio2 {
    background: url('http://www.xxxx.com/images/images/thumb_down-red-v2.png');
    background-repeat:no-repeat;
    cursor: pointer;
    width: 35px;
    height: 22px;
}

Answer №1

Here is a suggestion:

#txtradiocall #labelradio1 {
    background-image: url('http://placekitten.com/35/22');
}
#txtradiocall #labelradio2 {
    background-image: url('http://placekitten.com/35/22');
}

#txtradiocall label {
    padding: 0 40px 0 0;
    cursor: pointer;
    width: 35px;
    height: 22px;
    background-position: 100% 50%;
    background-repeat: no-repeat;
}

Check out the JS Fiddle demo here.

In the code above, we specifically define the background-image property instead of using shorthand notation. This prevents conflicts that may arise with other properties like background-repeat and background-position when using shorthand notation.

It's also a good practice to group shared properties together to ensure consistency and easier maintenance of the code.

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

Exploring Laravel 4's CSS Routing

Attempting to connect my CSS document in Laravel 4 has been a bit challenging. The location of my CSS file is: public/css/style.css In the view, I have the following link: <link type="text/css" rel="stylesheet" href="{{URL::asset('css/style.css ...

Guide to personalizing the ngxDaterangepickerMd calendaring component

I need to customize the daterangepicker library using ngxDaterangepickerMd in order to separate the start date into its own input field from the end date. This way, I can make individual modifications to either the start date or end date without affectin ...

Embedding PHP script within HTML code can enhance website functionality and

I am completely new to PHP and have never worked with it before. I'm interested in running a PHP script from within an HTML file on a Linux system. Can anyone guide me through the process? Below is the code from my HTML file: <!DOCTYPE HTML PUBLI ...

The IE browser does not allow clicking on anchors

My button/link is not clickable in Internet Explorer, but it works fine in Microsoft Edge and other modern browsers. I can't figure out what's wrong with the code. Any suggestions? <div class="bttn"> <a href="2.html">Next page</a ...

Tips for incorporating three background images within one CSS file

Here's a snippet of my navigation code: <? if($page == ""){ ?> <li> <a href="<? echo $site;?>" id="on" style="background-image:url(images/logonav_onright.png) right no-repeat;">Home</a> </li> ...

Progress Bar Flexbox Animation - Width Issue

I'm struggling to implement a progress bar with animation. It seems to work fine when there is no inner text, but as soon as I add some text, the width calculations get messed up. I've experimented with different width() functions and tried addin ...

Tips for aligning images and text in the center of a row using Bootstrap

I am struggling to center the image along with the text in my code. I attempted to use a container, but it did not have the desired effect. Below is the image: https://i.sstatic.net/fnaj4.png <section id="features"> <!-- <div ...

The conclusion of jQuery's nested animation

Functioning, But Page Transitions Inconsistent What I Believe to be the Correct Approach, But Event Triggering Issue Currently, I am experimenting with page transitions and utilizing bind() to detect the end of the CSS event transition. When a class is ad ...

Troubleshooting Vue 3: Issues with retrieving input field values

Vue 3 has been a bit challenging for me to grasp, especially related to making axios calls and handling input field values. In my Vue installation folder, I am trying to retrieve input values from the form fields to implement a login function which at lea ...

What steps can I take to make this JavaScript burger menu function properly?

I've been following an online tutorial to spice up my navigation bars a bit, but I'm having trouble getting my burger menu and animations to work. I've included the JS file above </body> (I also tried moving it into the <head>). ...

Display intricate header and preview in a printed datatable

Hey there, I've been using the Datatable plugin and it's really great. However, I've come across a problem with complex headers like this: <thead> <tr><td>some text</td></tr> <tr><td>some te ...

Curved edges conceal excess content + alter (Works in Firefox & Safari, but not in Chrome or Opera)

Trying to create rounded corners for a div to mask its children's content led me to a solution I found in this question. However, it appears that the solution does not work when the children elements are transformed. The following http://jsfiddle.net ...

Recently, there has been an issue with the size of SVG images specifically on Android Chrome

UPDATE: I have narrowed down the issue to two SVG images that can be found here: . Strangely, Chrome on Android is displaying the second SVG image underneath the first. Take a look at this screenshot of the incorrect rendering on the Chrome browser for And ...

The div containing the background image does not resize properly when using media queries

page in question. I am currently working on a chess board project where each cell is represented by a div element. My goal is to make the board expand beyond certain minimum widths using media queries, but for some reason, this functionality is not working ...

sticky bootstrap datepicker anchored to the top of the screen

Currently, I am working on a form that includes a date picker using the bootstrap datepicker In this setup, I have hidden the main bootstrap field and added three custom fields. When any of these fields are clicked, the calendar should open next to them. ...

Exploring Selenium with Java: Uncovering the Method to Locate and Identify a Specific Nested Element When Sharing Identical Parent Elements

If I have a page structured like this: <div class = "A"> <h1>AA</h1> <p>This</p> </div> <div class = "A"> <h1>BB</h1> <p>This</p> </div> And each time the page is loaded ...

Staggered Drop-Down Menus

I've created a custom CSS drop-down menu that works well, but I've realized that updating this menu across all the HTML pages on my website would be a tedious task. If I ever need to add a new section and tier to the menu, I'd have to update ...

How to Implement Snap-Enabled Dragging in a Container Using jQuery UI

Issue Description (Fiddle): I am using the jQuery UI's .draggable() function to make the red element snap inside the blue container. However, it is snapping to one edge only instead of completely fitting inside (both edges). It requires further dragg ...

What is a reliable method to retrieve the text from the current LI if all LI elements in the list share the

I'm encountering an issue with retrieving the text from LI elements because I have 10 list items and they all have the same class name. When I attempt to fetch the text using the class name or id, I only get the text of the last item. Here is my code ...

Customize global styles in React using the `react-helmet` library with a `:root`

Is it possible to enhance global styles in React by adding a :root style block with CSS variables? I included the following code snippet in my layout.tsx file, but when I run it in Visual Studio 2022 React project, the page appears blank. However, if I rep ...