Replace radio buttons with images displayed in a single row

.form-group {
    height: 16px;
}

.form-group > input {
    opacity: 0;
    position: absolute;
}

.form-group > input + label {
    background-image: url('Empty_Star.png');
    background-repeat: no-repeat;
    background-position: 0 0;
    padding: 0 0 0 0;
    display:block;
    height: 16px;
    vertical-align: middle;
    line-height:16px;
}
.form-group > input[type=radio]:checked + label {
    background-position: 0 0;
}

<form name="rating" class="form-group">
        <input id="radio1" type="radio" name="rate" value="1"/>
        <label for="radio1"></label>
        <input id="radio2" type="radio" name="rate" value="2"/>
        <label for="radio2"></label>
        <input id="radio3" type="radio" name="rate" value="3"/>
        <label for="radio3"></label>
        <input id="radio4" type="radio" name="rate" value="4"/>
        <label for="radio4"></label>
        <input id="radio5" type="radio" name="rate" value="5"/>
        <label for="radio5"></label>
</form>

Although I do not require labels, the tutorials I followed to replace radio buttons insisted on including them. If someone could provide guidance on how to remove them effectively, I would appreciate it. My primary concern is aligning each of the five star images side by side, as my attempts have been unsuccessful despite adjusting display options and referring to multiple tutorials. Thank you for any help!

Answer №1

*{
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

.form-group {
   /* height: 16px;*/
}
.form-group ul{}
.form-group ul li{    
    display: inline-block;
    *display: inline;
    zoom: 1;
    vertical-align: middle;
}

.form-group  input[type="radio"] {
    display: none;
}

.form-group  input[type="radio"] + label {
    background-image: url('http://www.iconsearch.ru/uploads/icons/uidesignicons/16x16/star_full.png');
    background-repeat: no-repeat;
    background-position: 0 0;
    padding: 0 0 0 0;
    display:block;
    height: 16px;
    vertical-align: middle;
    line-height:16px;
}
.form-group input[type=radio]:checked + label {
    /*background-position: 0 0;*/
    background: url(http://www.iconsearch.ru/ajax/download.php?icon_id=14617&size=1&format=ico);
}
label{
    display: block;
    width: 16px;
    height: 16px;
}
<form name="rating" class="form-group">
        <ul>
       <li><input id="radio1" type="radio" name="rate1" value="1"/>
        <label for="radio1"></label>
        <li><input id="radio2" type="radio" name="rate2" value="2"/>
        <label for="radio2"></label>
        <li><input id="radio3" type="radio" name="rate3" value="3"/>
        <label for="radio3"></label>
        <li><input id="radio4" type="radio" name="rate4" value="4"/>
        <label for="radio4"></label>
        <li><input id="radio5" type="radio" name="rate5" value="5"/>
        <label for="radio5"></label>
    </ul>
</form>

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

Is there a way to modify the button's color upon clicking in a React application?

I am a beginner in the world of React and currently exploring how to utilize the useState hook to dynamically change the color of a button upon clicking. Can someone kindly guide me through the process? Below is my current code snippet: import { Button } ...

Events triggered when a Jquery checkbox is toggled between checked and unchecked

I have written some HTML code that utilizes jQuery to manage checkboxes. <tr> <td> <div class="checkbox"> <label><input type="checkbox" id="checkbox2"></label> </div> </td> & ...

The issue with the JQuery Cookie Plugin is that it is unable to function properly due to the

Although I know there are many similar questions out there, please bear with me. I am not as proficient in JQuery as I am with HTML/CSS, and this is my first time using cookies. On my website, I have a green banner that should disappear when the user click ...

error in css styling detected

Why was the CSS style "background-position: center;" missed? It was because the background will override the background-position property. <html> <head> <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" ...

Determine the vertical dimension of an element through a JavaScript event listener

I've been working on creating an Apple-style image sequence scroller from a codepen demo. Here's the link to the original: https://codepen.io/jasprit-singh/pen/LYxzQjB My goal is to modify the JavaScript so that the scroll height is based on a p ...

Is there a specific location where the font size for input is determined?

Imagine you have a webpage with a table containing <input> elements within some of its cells. Currently, the font-size attribute of the <input> elements is set to 13px. Your goal is to change this font-size attribute to 12px. To begin, you wa ...

Switch Button in HTML

I am trying to implement a toggle button on my website, but unfortunately it is not working properly. Here is the HTML code I am using: <html> <head> <link rel="stylesheet" type="text/css" href="style.css" media="screen"> <script typ ...

Even after applying the CSS property "resize:none" to my HTML textarea, I still find it to be adjustable in size when viewed in the Opera browser

I'm currently working on customizing my HTML page and I want to ensure that all text inputs are consistent in size. I attempted to use the text-area selector in CSS, but it didn't seem to work correctly in Opera. The resize handle disappeared in ...

Div with headers that stick to the top and stack when scrolling

I am working on creating a lengthy scrollable list of grouped items where the group titles remain visible at all times (stacked). When a user clicks on a group header, the page should scroll to the corresponding items. I have successfully used the positio ...

Customize material-ui button designs using styled-components

I'm currently facing an issue with overriding the border-radius of a material-ui button using styled-components. Despite setting it to 0, it's not taking effect. Here is the code snippet: import React from "react"; import styled from "styled-co ...

Obtain the Base64 encoding from the URL of an image

I am attempting to convert an image into a base64 string by providing its URL. Here is the HTML code: <input type="text" value="" id="urlFileUpload"/> <input type="button" id="btn" value="GO" /> And here is the JavaScript code: $('#btn ...

Tips for ensuring that the elements within the flexbox are centered and aligned to the left

New proposed layout I need assistance with centering all flexbox items in a 3-column layout. Additionally, I want the items in rows that are not full to be centered and aligned to the left. Any suggestions for achieving this? Below is my current code, bu ...

Having trouble aligning the unordered list with the input

Can anyone help me troubleshoot my CSS so that the list appears below the input field? Check out this example The nested menu in this example is positioned too far to the left and slightly too high. It should be aligned with the bottom of the containing ...

Adding different colors for a range of values in the Grey_CircularLinearGauge component of DOJO can be achieved by customizing the

I'm currently working with the dojo toolkit and I am looking to incorporate the Grey_CircularLinearGauge component into my project. Here is an example of how I want it to look: In addition, I also need to customize the colors based on specific value ...

Achieving horizontal alignment for divs in CSS can be challenging

Struggling to align three circular divs on my webpage, here's the code: <div class="row"> <div class="large-9 push-2 columns"> <div class="green"></div> <a href="#">Donnez</a> </div> <div cl ...

The element is failing to wrap correctly, as it appears incorrectly when the viewport is resized and scrolled to the right

Through experimentation with the most basic HTML setup, I made a startling discovery. It seems that the wrapping of the top <html> tag is malfunctioning in EVERY browser. In my setup, I have applied a yellow background color to the <html> elem ...

Issues with navigation menus in Bootstrap/Wordpress

My mobile drop-down menu is giving me some strange issues. When you toggle the button, the menu briefly appears just below the button before moving to its correct position. Sometimes it doesn't work at all, and clicking has no effect. You can witnes ...

Ways to repair an element

Can anyone help me troubleshoot the issue with my count text on a div block? It seems to be affected by changes in screen size. Normal https://i.stack.imgur.com/RZkgr.png On screen resize https://i.stack.imgur.com/hTdCG.png The Code: span.right-cor ...

Matching CSS attribute values with another attribute

Can CSS be used to target elements based on the value of another attribute? For instance: <div data-attr1="abc" data-attr2="def"></div> <div data-attr1="abc" data-attr2="abc"></div> I am looking for something like this (although i ...

Using custom woff2 fonts in Android applications created with Visual Studio Community and Cordova seems to be causing compatibility issues

Help Needed! I am facing an issue with my app created using Visual Studio Community and Cordova. Everything works perfectly when I simulate it on my PC, but when I install it on my phone, the fonts just won't display correctly. I have tried all the s ...