【问题标题】:Separate Label and Input分离标签和输入
【发布时间】:2013-12-29 20:37:45
【问题描述】:

我有一个label,其中包含一个带有背景图像的Input Radio。 正如你在这里看到的

我需要将“Ja”和“Nej”设置为左侧 5-10pix,但我似乎无法找到解决方案。 有人可以帮我吗?

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>

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;
}

【问题讨论】:

    标签: html css input radio-button label


    【解决方案1】:

    我建议:

    #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;
    }
    

    JS Fiddle demo.

    上面指定了background-image 属性,而不是简写,因为使用简写,基于id 的选择器会覆盖background-repeatbackground-position 的后续声明(因为简写定义了所有属性,@987654328 @、-repeat-position)。

    此外,在一处指定所有共享属性,这样更容易保持属性一致且更易于维护。

    【讨论】:

    • placekitten 摇滚..!虽然我自己更像是一个爱狗的人;但是由于(上次我检查过)placepuppies 不存在,我很乐意将小猫应用于任何图片问题。 =D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-09
    • 2013-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-12
    相关资源
    最近更新 更多