具有自定义设计的 ASP.NET 复选框

2024-05-22

有没有办法改变asp.net复选框的ui样式。 我试过这个:

.cabeceraCheckBoxNormal
{
    background:url("../../../ig_res/Default/images/ig_checkbox_off.gif") no-repeat;
    clear:left;
    margin:0;
    padding:0;
}

but the result is not what i looking for. Because the image appears near the control, and i can see the normal style near the image. Like thisenter image description here

编辑: 我决定检查生成的 html,我看到在 asp 复选框上设置的 ID 设置为一个跨度,里面是输入类型复选框... 所以我将样式更改为:

input[type="checkbox"]
{
    background:url("../../../ig_res/Default/images/ig_checkbox_off.gif") no-repeat;
    background-position: 3px 2px;
    display:block;
    clear:left;
    margin:0;
    padding:0;
}

但什么也没发生


到目前为止,获得自定义复选框效果的最佳方法是添加<label>元素通过以下方式与复选框链接for属性。然后隐藏复选框并设置标签的样式before伪元素作为您的复选框。

像这样的事情:

<input type='checkbox' id='myCheck'><label for='myCheck'>Magic!</label>

与CSS:

#myCheck { visibility: hidden; }

input[type=checkbox] + label::before {
    display:block;
    content:url('ig_checkbox_off.gif');
    position:relative;
}
input[type=checkbox]:checked + label::before {
    content:url('ig_checkbox_on.gif');
}

我创建了一个 jsFiddle 示例来演示:http://jsfiddle.net/f9tLemyy/ http://jsfiddle.net/f9tLemyy/

希望有帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

具有自定义设计的 ASP.NET 复选框 的相关文章

随机推荐