2016-05-27 17 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 ....:( –

相關問題