css如何使这个复选框变小

时间:2014-05-24 12:19:07

标签: html css

我有一个div,我想在其中加入一个客户复选框。

div是红色的。

请查看附件图片。我认为overflow为自动。

,复选框出了红色区域

如何使复选框变小?

enter image description here

请如何缩小复选框

1 个答案:

答案 0 :(得分:1)

HTML中的更正。您在输入中具有相同的ID,并且标签中具有相同的引用for属性,这可能不起作用。 更新了HTML:

<div ID="campaignDiv" runat="server">
    <ul>
        <li>
            <input type="checkbox" id="1" value="1" />
            <label for="1"></label>
        </li>
        <li>
            <input type="checkbox" id="2" value="1" />
            <label for="2"></label>
        </li>
        <li>
            <input type="checkbox" id="3" value="1" />
            <label for="3"></label>
        </li>
        <li>
            <input type="checkbox" id="4" value="1" />
            <label for="4"></label>
        </li>
    </ul>
</div>

要缩小尺寸,只需使用top,left,height,width,font-size属性:

#campaignDiv {
    background-color: red;
    padding-bottom: 10px;
    position: absolute;
    top: 40px;    
}
#campaignDiv ul {
    color: #fff;
    list-style: none;    
}
#campaignDiv input[type=checkbox] {
    visibility: hidden;
}
#campaignDiv input[type=checkbox]:checked + label {
    left: 60px;
    background: #26ca28;
}
#campaignDiv li {
    width: 120px;
    background: #333;
    margin: 10px 30px;//Changed
    border-radius: 30px;//Changed
    position: relative;
}
#campaignDiv li:before {
    content:'On';
    position: absolute;
    top: 3px;//Changed
    left: 13px;
    height: 2px;
    color: #26ca28;
    font-size: 12px;//Changed
}
#campaignDiv li:after {
    content:'Off';
    position: absolute;
    top: 4px;//Changed
    left: 84px;
    height: 2px;
    color: #111;
    font-size: 12px;//Changed
}
#campaignDiv li label {
    display: block;
    width: 40px;//Changed
    height: 14px;//Changed
    border-radius: 50px;
    -webkit-transition: all .5s ease;
    -moz-transition: all .5s ease;
    -o-transition: all .5s ease;
    -ms-transition: all .5s ease;
    transition: all .5s ease;
    cursor: pointer;
    position: absolute;
    top: 4px;//Changed
    z-index: 1;
    left: 12px;
    background: #ddd;
}

您可以将CSS与css进行比较,以了解代码中所做的更改。

相关问题