2017-02-14 3 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>