由于背景图像,css样式单选按钮不起作用

时间:2014-09-05 02:03:55

标签: css html5 css3 background radio

我正在使用来自http://www.csscheckbox.com/

的样式化css单选按钮

问题是他们手动给出单选按钮高度(即30px),文本溢出下一行。

Isuse image

所以我试图去除手动高度。然后,当背景图像用作背景位置时,存在更多问题:(

More problem

此处使用的背景图片如下图所示。

enter image description here

这是单选按钮的css脚本。

input[type=radio].css-checkbox {
    display:none;
}

input[type=radio].css-checkbox + label.css-label {
    padding-left:35px;
    height:30px;
    display:inline-block;
    line-height:30px;
    background-repeat:no-repeat;
    background-position: 0 0;
    font-size:20px;
    vertical-align:middle;
    cursor:pointer;

}

input[type=radio].css-checkbox:checked + label.css-label {
    background-position: 0 -30px;
}
label.css-label {
    background-image:url({{ URL::to('/') }}/application/assets/img/checkbox.png);
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

这是Markup。

<ul>
     <li><input type="radio" name="answer2671" id="radio12344" class="css-checkbox" value="1" /><label for="radio12344" class="css-label radGroup1">Planning and strategy</label></li>
     <li><input type="radio" name="answer2671" id="radio12345" class="css-checkbox" value="2" /><label for="radio12345" class="css-label radGroup1">Supporting your teammates</label></li>
     <li><input type="radio" name="answer2671" id="radio12346" class="css-checkbox" value="3" /><label for="radio12346" class="css-label radGroup1">Motivating everyone</label></li>
     <li><input type="radio" name="answer2671" id="radio12347" class="css-checkbox" value="4" /><label for="radio12347" class="css-label radGroup1">Courage in the face of adversity</label></li>
  </ul>

感谢任何形式的帮助!

2 个答案:

答案 0 :(得分:0)

删除高度,行高,并在标签上添加一些顶部和底部填充。

input[type=radio].css-checkbox + label.css-label {
padding:20px 0 20px 35px;
display:inline-block;
background-repeat:no-repeat;
background-position: 0 0;
font-size:20px;
vertical-align:middle;
cursor:pointer;
}

答案 1 :(得分:0)

将CSS更改为:

ul {
    width:240px;
}
li {
    list-style-type:none;
    padding:5px 5px;
    margin:5px 0 20px;
    line-height:15px
}
input[type=radio].css-checkbox {
    display:none;
}
.quiz-question-block.qhidden {
    display:none;
}
input[type=radio].css-checkbox + label.css-label {
    padding-left:45px;
    height:32px;
    display:inline-block;
    line-height:30px;
    background-repeat:no-repeat;
    background-position: 0 0;
    font-size:20px;
    vertical-align:middle;
    cursor:pointer;
}
input[type=radio].css-checkbox:checked + label.css-label {
    background-position: 0 -32px;
}
label.css-label {
    background-image:url('http://i.stack.imgur.com/KLQO2.png');
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

您需要根据自己的需要进行调整,我还限制了表单的宽度以实现可视化目的,但您会明白这一点

See fiddle here

编辑:另一种选择是修改图像并使其更大,两种状态之间有很大的分离,只需将CSS调整为新的图像尺寸

相关问题