2016-05-27 19 views
2

我有以下的html代码:如何更改引导复选框的颜色?

<div class="container"> 
    <form name="queryForm" class="form-inline text-center"> 
    <p class="checkbox-inline"> 
     <input type="checkbox" name="optionsRadios" id="checkOther" value="other" ng-model="formData.other" ng-true-value="'other'" ng-init="formData.other='other'">Other</p> 
    </form> 
</div> 

和的结果是:

enter image description here

什么改变这种颜色给定一个,例如D7B1D7的最简单的方法是什么?

+1

伴侣,这里回答这里http://stackoverflow.com/questions/28768623/how-do-you-change-the-style-of-a-bootstrap-checkbox和这里http://stackoverflow.com/问题/ 26821895 /更改颜色复选框标签时检查希望你得到它的工作。 – user3620318

+0

链接到引导CSS的HTML代码不会重现您显示的结果。你使用一些插件还是有一些HTML(引导类缺失?因为一种方式是http://codepen.io/anon/pen/MeWemd –

+0

我的答案有帮助吗?如果没有,请随时提出任何问题。 – Yass

回答

2

我已经适应从这个CodePen.squaredThree类的实例。如果你想看一个实例,我的答案底部有一个小提琴链接。

下面是更新后的CSS:

/* .squaredThree */ 
.squaredThree { 
    position: relative; 
    float:left; 
} 

.squaredThree label { 
    width: 20px; 
    height: 20px; 
    cursor: pointer; 
    position: absolute; 
    top: 0; 
    left: 0; 
    background: #D7B1D7; 
    border-radius: 4px; 
    box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.5), 0px 1px 0px rgba(255, 255, 255, 0.4); 
} 

.squaredThree label:after { 
    content: ''; 
    width: 9px; 
    height: 5px; 
    position: absolute; 
    top: 4px; 
    left: 4px; 
    border: 3px solid #fcfff4; 
    border-top: none; 
    border-right: none; 
    background: transparent; 
    opacity: 0; 
    -webkit-transform: rotate(-45deg); 
    transform: rotate(-45deg); 
} 

.squaredThree label:hover::after { 
    opacity: 0.3; 
} 

.squaredThree input[type=checkbox] { 
    visibility: hidden; 
} 

.squaredThree input[type=checkbox]:checked + label:after { 
    opacity: 1; 
} 
/* end .squaredThree */ 

我已经更新了你的HTML包含另一个label,作为原始label被用作伪复选框。这是你的更新HTML:

<div class="container"> 
    <form name="queryForm" class="form-inline"> 
    <div class="squaredThree"> 
     <input type="checkbox" name="optionsRadios" id="checkOther" value="other" ng-model="formData.other" ng-true-value="'other'" ng-init="formData.other='other'"> 
     <label for="checkOther"></label> 
    </div> 
    <label class="label-text">Other</label> 
    </form> 
</div> 

注意,附加label存在.squaredThreediv之外。该label有一类.label-text一些附加的样式规则的文字稍微移动到checkbox权需要:

.label-text { 
    position: relative; 
    left: 10px; 
} 

最后,检查在checkbox大小是不完全正确的,从而需要额外的规则来纠正:

*, 
::before, 
::after { 
    box-sizing: initial; 
} 

Fiddle Demo显示上述行动。

+1

非常感谢你,我查看了你的小提琴,它的工作很好,我只是有一个问题 - 是否有更新的HTML代码的方式,使我有3个复选框相邻的?我想要什么实现这是http://imgur.com/6onY6GA,我认为它应该足以复制的HTML代码三次,但这是结果https://jsfiddle.net/pvyp4mL3/3/我在这里做错了什么? – user3766930

+1

如果你用'.container'类包装每个复选框,它可以解决这个问题:https://jsfiddle.net/yassarikhan786/pvyp4mL3/ – Yass

+0

谢谢@Yass !!那么有没有办法把这些复选框和他们的标签彼此相邻,而不是彼此之上?:) – user3766930

-2

input[type=checkbox]没有background-color属性。您可以使用其他方式来获得您理想的结果:

  1. 您可以使用复选框一个div内,然后根据自己的需要风格的股利。

    <div class="row"> 
        <input type="checkbox" /> 
    </div> 
    
  2. 您可以使用伪元素这样的:

    input[type=checkbox] { 
        cursor: pointer; 
        } 
    
    input[type=checkbox]:after { 
        content: " "; 
        background-color: #D7B1D7; 
        display: inline-block; 
        visibility: visible; 
    } 
    
    input[type=checkbox]:checked:after { 
        content: "\2714"; 
    } 
    
+0

谢谢,我试过你的第二种方法,这就是我得到的:http:///imgur.com/uS3J5ou它看起来并不是我想要的样子......你能告诉我一些关于第一点的例子吗? – user3766930

+0

你可以发送图片/快照/链接怎么样? – Mona

+0

它不适用于FF ....:( –

相关问题