2016-07-13 2 views
0

Я пытаюсь разработать пользовательскую кнопку переключения и атташе перед текстом. Я хочу, чтобы текст и переключатель были в одной строке. Но текст идет в одной строке и переключается в другую.Отображать текст и настраивать Toggle в той же строке

Рабочий код: https://jsfiddle.net/nvarun123/x6v1nevw/1/

Когда я добавить стиль display:inline-block; затем форму тумблера круга становится нарушается. Я пытаюсь развить это в 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 { 
    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; 

} 

ответ

0

Ваш onoffswitch класс применяется к сНу элемента, который по умолчанию имеет дисплей значение «блок». Элементы блока по умолчанию будут отображаться в отдельной строке.

Добавить этот стиль в onoffswitch класс:

display: inline-block; 
+0

Привет, когда я добавить дисплей: встроенный блок; круг кнопки переключения выходит из строя. Я прикрепил код плунжера: http://plnkr.co/edit/4ZnrnJbSyFAp5c6Z0V7T?p=preview. Я разрабатываю компонент в Angular2 для его повторного использования. – Varun

Смежные вопросы