2017-02-14 9 views
0

下のトグルの右側にラベルを追加するにはどうすればいいですか?トグルボタンの右にラベルを追加

正しく整列されていないラベルを追加しようとしました。

何か助けがありがたいです。

Plunkrリンク - https://plnkr.co/edit/NdnF2OycDZpk2FiiB7D6?p=preview

index.htmlを

<!DOCTYPE html> 
<html> 
<head> 
<style> 
.switch { 
    position: relative; 
    display: inline-block; 
    width: 47px; 
    height: 20px; 
} 

.switch input {display:none;} 

.slider { 
    position: absolute; 
    cursor: pointer; 
    top: 0; 
    left: 0; 
    right: 0; 
    bottom: 0; 
    background-color: #ccc; 
    -webkit-transition: .4s; 
    transition: .4s; 
} 

.slider:before { 
    position: absolute; 
    content: ""; 
    height: 13px; 
    width: 13px; 
    left: 4px; 
    bottom: 4px; 
    background-color: white; 
    -webkit-transition: .4s; 
    transition: .4s; 
} 

input:checked + .slider { 
    background-color: #2196F3; 
} 

input:focus + .slider { 
    box-shadow: 0 0 1px #2196F3; 
} 

input:checked + .slider:before { 
    -webkit-transform: translateX(26px); 
    -ms-transform: translateX(26px); 
    transform: translateX(26px); 
} 

/* Rounded sliders */ 
.slider.round { 
    border-radius: 34px; 
} 

.slider.round:before { 
    border-radius: 50%; 
} 
</style> 
</head> 
<body> 

<label class="switch"> 
    <input type="checkbox" checked> 
    <div class="slider round"></div> 
</label> 

</body> 
</html> 
+0

私は答えを持っているが、それは、ディスプレイ使用しています:フレックス、古いブラウザのための答えが必要なのでしょうか、それは十分だろうか? – d3orn

+0

これがあなたを助けてくれることを願っています。リンクを確認してくださいhttps://fiddle.jshell.net/h1vuuz2t/ –

+0

このクラスにCSSを追加:.switch {float:left;} –

答えて

1

あなたは、CSSを使用して(::後)と目的の場所に配置する位置を使用してラベルにコンテンツを追加することができます。

.switch { 
 
    position: relative; 
 
    display: inline-block; 
 
    width: 47px; 
 
    height: 20px; 
 
} 
 

 
.switch input {display:none;} 
 

 
.slider { 
 
    position: absolute; 
 
    cursor: pointer; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0; 
 
    bottom: 0; 
 
    background-color: #ccc; 
 
    -webkit-transition: .4s; 
 
    transition: .4s; 
 
} 
 

 
.slider:before { 
 
    position: absolute; 
 
    content: ""; 
 
    height: 13px; 
 
    width: 13px; 
 
    left: 4px; 
 
    bottom: 4px; 
 
    background-color: white; 
 
    -webkit-transition: .4s; 
 
    transition: .4s; 
 
} 
 

 
input:checked + .slider { 
 
    background-color: #2196F3; 
 
} 
 

 
input:focus + .slider { 
 
    box-shadow: 0 0 1px #2196F3; 
 
} 
 

 
input:checked + .slider:before { 
 
    -webkit-transform: translateX(26px); 
 
    -ms-transform: translateX(26px); 
 
    transform: translateX(26px); 
 
} 
 

 
/* Rounded sliders */ 
 
.slider.round { 
 
    border-radius: 34px; 
 
} 
 

 
.slider.round:before { 
 
    border-radius: 50%; 
 
} 
 

 
.slider::after { 
 
    position:relative; 
 
    right:-55px; 
 

 
    content: "label" 
 
}
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
</head> 
 
<body> 
 

 
<label class="switch"> 
 
    <input type="checkbox" checked> 
 
    <div class="slider round"></div> 
 
</label> 
 

 
</body> 
 
</html>

0

は、私はそれが動作する必要がありますね、以下のコードを試してみてください。

.switch { 
    position: relative; 
    display: inline-block; 
    width: 47px; 
    height: 20px; 
} 

.switch input { 
    display: none; 
} 

.slider { 
    position: absolute; 
    cursor: pointer; 
    top: 0; 
    left: 0; 
    right: 0; 
    bottom: 0; 
    background-color: #ccc; 
    -webkit-transition: .4s; 
    transition: .4s; 
} 

.slider:before { 
    position: absolute; 
    content: ""; 
    height: 13px; 
    width: 13px; 
    left: 4px; 
    bottom: 4px; 
    background-color: white; 
    -webkit-transition: .4s; 
    transition: .4s; 
} 

.switch span { 
    display: inline-block; 
    position: relative; 
    width: 60px; 
    margin-left: 50px; 
} 

input:checked + .slider { 
    background-color: #2196F3; 
} 

input:focus + .slider { 
    box-shadow: 0 0 1px #2196F3; 
} 

input:checked + .slider:before { 
    -webkit-transform: translateX(26px); 
    -ms-transform: translateX(26px); 
    transform: translateX(26px); 
} 
/* Rounded sliders */ 

.slider.round { 
    border-radius: 34px; 
} 

.slider.round:before { 
    border-radius: 50%; 
} 

<body> 

    <label class="switch"> 
    <input type="checkbox" checked> 
    <div class="slider round"></div> 
    <span>LABEL 1</span> 
    </label> 

</body> 
関連する問題