0
나는 사용자 정의 토글 버튼을 개발하고 그 앞에 텍스트를 첨부하려고합니다. 텍스트와 토글을 같은 줄에 넣기를 원합니다. 그러나 텍스트는 한 줄에 나오고 다른 글은 토글됩니다.텍스트와 사용자 정의 토글을 같은 줄에 표시
작업 코드 :
난 후 스타일 display:inline-block;
토글 원의 모양을 추가 https://jsfiddle.net/nvarun123/x6v1nevw/1/이 방해를 받고있다. Angular2에서이를 컴포넌트로 개발하려고합니다. Angular2에서 워킹 코드 : http://plnkr.co/edit/4ZnrnJbSyFAp5c6Z0V7T?p=preview
HTML 코드 :
<div style="display:inline;">
Toggle1:
<div class="onoffswitch" style="margin-bottom:5px;">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked >
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</div>
<div style="display:inline;">
Toggle2:
<div class="onoffswitch" style="margin-bottom:5px;">
<input type="checkbox" name="onoffswitch1" class="onoffswitch-checkbox" id="myonoffswitch1" >
<label class="onoffswitch-label" for="myonoffswitch1">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</div>
CSS 코드 : 귀하의 onoffswitch 클래스는 기본적으로의 표시 값을 가진 div 요소에 적용되는
.onoffswitch {
position: relative; width: 50px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border-radius: 10px;
}
.onoffswitch-inner {
display: block; width: 200%; margin-left: -100%;
transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
display: block; float: left; width: 50%; height: 22px; padding: 0; line-height: 22px;
font-size: 10px; color: white; font-family: sans-serif; font-weight: bold;
box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "";//ON
padding-left: 8px;
background-color: lightgreen;
color: pink;
}
.onoffswitch-inner:after {
content: "";//OFF
padding-right: 6px;
background-color: red;
color: #F9FAFB;
text-align: right;
}
.onoffswitch-switch {
display: block; width: 20px; margin: 0px;
background: #F9FAFB;
position: absolute; top: 0; bottom: 0;
right: 30px;
border-radius: 20px;
transition: all 0.3s ease-in 0s;
box-shadow: 0.276px 0.961px 2px 0px rgba(0, 0, 0, 0.1);
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}
안녕, 내가 표시 추가 :
onoffswitch 클래스에이 스타일을 추가 인라인 블록; 토글 버튼의 원이 모양에서 벗어나고 있습니다. 나는 plunker 코드를 첨부했습니다 : http://plnkr.co/edit/4ZnrnJbSyFAp5c6Z0V7T?p=preview. 다시 사용하려면 Angular2에서 구성 요소를 개발 중입니다. – Varun