css - 使单选按钮替换为同一行中的图像

标签 css image radio-button

.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>

我不需要那里的标签,但是每个关于如何替换单选按钮的教程都包含它们并且不包含它们都不起作用。因此,对此的任何帮助也表示赞赏。但我的主要问题是让五颗星(图像)并排排列。无论我做什么都行不通。我试过使用显示选项并阅读其他教程。一切都无法正常工作。谢谢!

最佳答案

*{
    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>

关于css - 使单选按钮替换为同一行中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30314672/

相关文章:

css - CSS 中的位置属性

html - 在悬停时更改图像和链接

html - Bootstrap 轮播指示器无法正常工作

java - Struts2 标签单选按钮

java - Vaadin 14 单选按钮组显示自定义字符串作为选项

html - 全宽网页

c# - c# 中的 pictureBox.Image.Save() 不起作用

javascript - 如何测量base 64图像的大小?

android - 使用 Volley 或 Picasso 从 URL 加载并显示 WebM 和 Gif 到 ImageView

php - html.php 表单将 bool 单选按钮值呈现为 `on`