2017-05-04 12 views
1

ラジオボタンを選択するとラジオが青色に変わります。でも、私は出来ません。これは私のCSSコードです:CSSボーダーを入力タイプのラジオに変更しました

/* Estilo Radio Button */ 
.radio { 
    padding-left: 25px; 
} 

.radio label { 
    display: inline-block; 
    position: relative; 
    padding-left: 0px; 
} 

.radio label::before { 
    content: ""; 
    display: inline-block; 
    position: absolute; 
    width: 17px; 
    height: 17px; 
    left: 0; 
    margin-left: -20px; 
    border: 1px solid #cccccc; 
    border-radius: 50%; 
    border-color: #ddd !important; 
    outline: 0 !important; 
    background-color: #fff; 
    -webkit-transition: border 0.15s ease-in-out; 
    -o-transition: border 0.15s ease-in-out; 
    transition: border 0.15s ease-in-out; 
} 

.radio label:hover:before { 
    border-color: rgba(82, 168, 236, 0.8) !important; 
    outline: 0 !important; 
    outline: thin dotted \9 !important; 
    -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6) !important; 
    -moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6) !important; 
    box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6) !important; 
} 

.radio label::after { 
    display: inline-block; 
    position: absolute; 
    content: " "; 
    width: 11px; 
    height: 11px; 
    left: 3px; 
    top: 3px; 
    margin-left: -20px; 
    border-radius: 50%; 
    background-color: #555555; 
    -webkit-transform: scale(0, 0); 
    -ms-transform: scale(0, 0); 
    -o-transform: scale(0, 0); 
    transform: scale(0, 0); 
    -webkit-transition: -webkit-transform 0.1s cubic-bezier(0.8, -0.33, 0.2, 1.33); 
    -moz-transition: -moz-transform 0.1s cubic-bezier(0.8, -0.33, 0.2, 1.33); 
    -o-transition: -o-transform 0.1s cubic-bezier(0.8, -0.33, 0.2, 1.33); 
    transition: transform 0.1s cubic-bezier(0.8, -0.33, 0.2, 1.33); 
} 

.radio input[type="radio"] { 
    opacity: 0; 
} 

.radio input[type="radio"]:focus + label::before { 
    outline: thin dotted; 
    outline: 5px auto -webkit-focus-ring-color; 
    outline-offset: -2px; 
} 

.radio input[type="radio"]:checked + label::after { 
    -webkit-transform: scale(0.75, 0.75); 
    -ms-transform: scale(0.75, 0.75); 
    -o-transform: scale(0.75, 0.75); 
    transform: scale(0.75, 0.75); 
} 

.radio input[type="radio"]:disabled + label { 
    opacity: 0.65; 
} 

.radio input[type="radio"]:disabled + label::before { 
    cursor: not-allowed; 
} 

.radio.radio-inline { 
    margin-top: 0; 
} 

.radio-primary input[type="radio"] + label::after { 
    background-color: #428bca; 
} 

.radio-primary input[type="radio"]:checked + label::before { 
    border-color: #428bca; 
} 

.radio-primary input[type="radio"]:checked + label::after { 
    background-color: #428bca; 
} 


.radio-danger input[type="radio"] + label::after { 
    background-color: #d9534f; 
} 

.radio-danger input[type="radio"]:checked + label::before { 
    border-color: #d9534f; 
} 

.radio-danger input[type="radio"]:checked + label::after { 
    background-color: #d9534f; 
} 

.radio-info input[type="radio"] + label::after { 
    background-color: #5bc0de; 
} 

.radio-info input[type="radio"]:checked + label::before { 
    border-color: #5bc0de; 
} 

.radio-info input[type="radio"]:checked + label::after { 
    background-color: #5bc0de; 
} 

.radio-warning input[type="radio"] + label::after { 
    background-color: #f0ad4e; 
} 

.radio-warning input[type="radio"]:checked + label::before { 
    border-color: #f0ad4e; 
} 

.radio-warning input[type="radio"]:checked + label::after { 
    background-color: #f0ad4e; 
} 

.radio-success input[type="radio"] + label::after { 
    background-color: #5cb85c; 
} 

.radio-success input[type="radio"]:checked + label::before { 
    border-color: #5cb85c; 
} 

.radio-success input[type="radio"]:checked + label::after { 
    background-color: #5cb85c; 
} 

私はこれを変更した場合:

.radio label::before { 
    content: ""; 
    display: inline-block; 
    position: absolute; 
    width: 17px; 
    height: 17px; 
    left: 0; 
    margin-left: -20px; 
    border: 1px solid #cccccc; 
    border-radius: 50%; 
    //HERE!!! 
    border-color: blue !important; 
    outline: 0 !important; 
    background-color: blue; 
    -webkit-transition: border 0.15s ease-in-out; 
    -o-transition: border 0.15s ease-in-out; 
    transition: border 0.15s ease-in-out; 
} 

は、すべてのラジオボタンの境界線を変更します。私はラジオボタンをチェックしただけです。どうすればいい?ありがとうございました。

+0

ため!importantスタイルを持っているので!importantが必要とされているように見えますか?入力とラベルの間に要素がある場合、 '+'は機能しません。代わりに '〜'が必要かもしれませんが、マークアップも見ることができない限り、私は確かに分かりません。 –

+0

HTMLなしどのように対応できますか? [mcve]を作成してください。 –

+1

[リンク1](http://stackoverflow.com/questions/4253920/how-do-i-change-the-color-of-radio-buttons)[リンク2](http:// www。 codeply.com/go/NKtDpPXv2x)[リンク3](https://help.surveygizmo.com/help/icons) – Nimish

答えて

1

をあなたのCSSとロコは一緒に入れたコードに基づいて必要

このデモは、SHの* tのように見えますが、それはあなたのCSSだ、私はあなたを考えますこの新しいルールが必要です。このようなルールがありますが、特定のクラスのコントロールにのみ適用されます。 .radio label::beforeのためのあなたのルールは、マークアップ何border-color

.radio input[type="radio"]:checked + label::before { 
    border-color: blue !important; 
} 
+0

ありがとうございます! – JuMoGar

-1

ラジオボタンのスタイリングは、ネイティブのブラウザ要素であるため変更できません。

How do I change the color of radio buttons?

あなたがラベルでやっていたように擬似要素を重ねてみることができます。しかし、より高いz-インデックスを持つもう一つのラジオボタン

+0

だから彼は「私はラジオボタンが選択されているときにそれを試していますが、ラジオを青色に変更しています。 「私はラジオボタンをチェックしただけだ」彼はラジオボタンを変更しようとしているわけではありませんか?あなたが投稿したのは彼がラベルを変更して、ボタンのスタイルではなく変更できることを示すことです。 – StefanBob

+0

はい... OPは実際にはラジオボタンの境界線の色を変更しようとはしませんでした。それはちょうど貧弱な言葉です。彼の例を見てください。彼は「私がこれを変更すれば:」と、「border-color:blue!important;」のスタイルを含む '.radio label :: before'のルールに続いて、「すべてのラジオボタンの境界線を変更する」と言います。それは、明確なOPは、ラベルの境界線について話していることです。 –

+0

あなたは間違っています。彼は私がこれをするとき、私はラベル/境界線を変えることができると言います。しかし、私はラジオボタンを変更することはできません。ラジオボタンを変更するにはどうすればいいですか?私は彼の質問に答えました。彼は実際のボタンではなくボタンの他​​の部分をどのようにスタイルすることができるかの例を示しているだけです。 – StefanBob

0

投稿したコードに何も問題はありません。
:checkedの状態を機能させることができない場合は、id=""とラベルfor=""の属性が不足していることを意味します。あなたはヒモアップする

/* Estilo Radio Button */ 
 
.radio { 
 
    padding-left: 25px; 
 
} 
 

 
.radio label { 
 
    display: inline-block; 
 
    position: relative; 
 
    padding-left: 0px; 
 
} 
 

 
.radio label::before { 
 
    content: ""; 
 
    display: inline-block; 
 
    position: absolute; 
 
    width: 17px; 
 
    height: 17px; 
 
    left: 0; 
 
    margin-left: -20px; 
 
    border: 1px solid #cccccc; 
 
    border-radius: 50%; 
 
    border-color: #ddd !important; 
 
    outline: 0 !important; 
 
    background-color: #fff; 
 
    -webkit-transition: border 0.15s ease-in-out; 
 
    -o-transition: border 0.15s ease-in-out; 
 
    transition: border 0.15s ease-in-out; 
 
} 
 

 
.radio label:hover:before { 
 
    border-color: rgba(82, 168, 236, 0.8) !important; 
 
    outline: 0 !important; 
 
    outline: thin dotted \9 !important; 
 
    -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6) !important; 
 
    -moz-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6) !important; 
 
    box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6) !important; 
 
} 
 

 
.radio label::after { 
 
    display: inline-block; 
 
    position: absolute; 
 
    content: " "; 
 
    width: 11px; 
 
    height: 11px; 
 
    left: 3px; 
 
    top: 3px; 
 
    margin-left: -20px; 
 
    border-radius: 50%; 
 
    background-color: #555555; 
 
    -webkit-transform: scale(0, 0); 
 
    -ms-transform: scale(0, 0); 
 
    -o-transform: scale(0, 0); 
 
    transform: scale(0, 0); 
 
    -webkit-transition: -webkit-transform 0.1s cubic-bezier(0.8, -0.33, 0.2, 1.33); 
 
    -moz-transition: -moz-transform 0.1s cubic-bezier(0.8, -0.33, 0.2, 1.33); 
 
    -o-transition: -o-transform 0.1s cubic-bezier(0.8, -0.33, 0.2, 1.33); 
 
    transition: transform 0.1s cubic-bezier(0.8, -0.33, 0.2, 1.33); 
 
} 
 

 
.radio input[type="radio"] { 
 
    opacity: 0; 
 
} 
 

 
.radio input[type="radio"]:focus + label::before { 
 
    outline: thin dotted; 
 
    outline: 5px auto -webkit-focus-ring-color; 
 
    outline-offset: -2px; 
 
} 
 

 
.radio input[type="radio"]:checked + label::after { 
 
    -webkit-transform: scale(0.75, 0.75); 
 
    -ms-transform: scale(0.75, 0.75); 
 
    -o-transform: scale(0.75, 0.75); 
 
    transform: scale(0.75, 0.75); 
 
} 
 

 
.radio input[type="radio"]:disabled + label { 
 
    opacity: 0.65; 
 
} 
 

 
.radio input[type="radio"]:disabled + label::before { 
 
    cursor: not-allowed; 
 
} 
 

 
.radio.radio-inline { 
 
    margin-top: 0; 
 
} 
 

 
.radio-primary input[type="radio"] + label::after { 
 
    background-color: #428bca; 
 
} 
 

 
.radio-primary input[type="radio"]:checked + label::before { 
 
    border-color: #428bca; 
 
} 
 

 
.radio-primary input[type="radio"]:checked + label::after { 
 
    background-color: #428bca; 
 
} 
 

 

 
.radio-danger input[type="radio"] + label::after { 
 
    background-color: #d9534f; 
 
} 
 

 
.radio-danger input[type="radio"]:checked + label::before { 
 
    border-color: #d9534f; 
 
} 
 

 
.radio-danger input[type="radio"]:checked + label::after { 
 
    background-color: #d9534f; 
 
} 
 

 
.radio-info input[type="radio"] + label::after { 
 
    background-color: #5bc0de; 
 
} 
 

 
.radio-info input[type="radio"]:checked + label::before { 
 
    border-color: #5bc0de; 
 
} 
 

 
.radio-info input[type="radio"]:checked + label::after { 
 
    background-color: #5bc0de; 
 
} 
 

 
.radio-warning input[type="radio"] + label::after { 
 
    background-color: #f0ad4e; 
 
} 
 

 
.radio-warning input[type="radio"]:checked + label::before { 
 
    border-color: #f0ad4e; 
 
} 
 

 
.radio-warning input[type="radio"]:checked + label::after { 
 
    background-color: #f0ad4e; 
 
} 
 

 
.radio-success input[type="radio"] + label::after { 
 
    background-color: #5cb85c; 
 
} 
 

 
.radio-success input[type="radio"]:checked + label::before { 
 
    border-color: #5cb85c; 
 
} 
 

 
.radio-success input[type="radio"]:checked + label::after { 
 
    background-color: #5cb85c; 
 
}
<span class="radio"> 
 
    <input type="radio" id="r1" name="r"> 
 
    <label for="r1"></label> 
 
</span> 
 

 
<span class="radio"> 
 
    <input type="radio" id="r2" name="r"> 
 
    <label for="r2"></label> 
 
</span>

+0

私の答えを見てください。あなたが私とあなたのものを結合するなら、私は先に進み、私のものを削除します。 –

+0

これは彼が望むものではありません。 – Nimish

関連する問題