Переключение ввода и ввода не является встроенным - PullRequest
0 голосов
/ 25 апреля 2018

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

Я пробовал сам Div вместо метки. Я пытался комбинировать метку и ввод, но либо я не получаю требуемый результат, либо он вообще не работает.

Вот код:

.uni_controls {
  margin: 5px;
  background-color: orange;
}

.uni_controls input {
  width: 150px;
  height: 35px;
  box-sizing: border-box;
  border-radius: 10px;
  border: 1px solid #00c1ff;
  color: #00c1ff;
  font-size: 10px;
  outline: none;
  text-align: center;
  background-color: white;
  margin: 2.5px;
}

.uni_controls label {
  position: relative;
  display: inline-block;
  width: 150px;
  height: 35px;
  outline: none;
  border-radius: 10px;
  border: 1px solid #00c1ff;
  margin: 2.5px;
}

.uni_controls label input {
  display: none;
}

.uni_controls label slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: white;
  transition: .4s;
  border-radius: 10px;
}

.uni_controls label slider:before {
  position: absolute;
  content: "";
  height: 27px;
  width: 27px;
  left: 4px;
  bottom: 4px;
  background-color: red;
  transition: .4s;
  border-radius: 8px;
}

.uni_controls label input:checked+slider {
  background-color: white;
}

.uni_controls label input:focus+slider {
  box-shadow: 0 0 1px pink;
}

.uni_controls label input:checked+slider:before {
  transform: translateX(115px);
}

slider:after {
  content: 'OFF';
  color: black;
  display: block;
  position: absolute;
  transform: translate(-50%, -50%);
  top: 50%;
  left: 50%;
  font-size: 10px;
  font-family: Verdana, sans-serif;
}

.uni_controls label input:checked+slider:after {
  content: 'ON';
}
<div class="uni_controls">
  <input placeholder="THIS IS TEST TB" />
  <label>
    <input type="checkbox">
    <slider>
  </label>
  <input placeholder="THIS IS TEST TB" />
  <input placeholder="THIS IS TEST TB" />
  <label>
    <input type="checkbox">
    <slider>
  </label>
  <label>
    <input type="checkbox">
    <slider>
  </label>

1 Ответ

0 голосов
/ 25 апреля 2018

Просто добавьте vertical-align: top; к .uni_controls input

.uni_controls {
  margin: 5px;
  background-color: orange;
}

.uni_controls input {
  vertical-align: top;
  width: 150px;
  height: 35px;
  box-sizing: border-box;
  border-radius: 10px;
  border: 1px solid #00c1ff;
  color: #00c1ff;
  font-size: 10px;
  outline: none;
  text-align: center;
  background-color: white;
  margin: 2.5px;
}

.uni_controls label {
  position: relative;
  display: inline-block;
  width: 150px;
  height: 35px;
  outline: none;
  border-radius: 10px;
  border: 1px solid #00c1ff;
  margin: 2.5px;
}

.uni_controls label input {
  display: none;
}

.uni_controls label slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: white;
  transition: .4s;
  border-radius: 10px;
}

.uni_controls label slider:before {
  position: absolute;
  content: "";
  height: 27px;
  width: 27px;
  left: 4px;
  bottom: 4px;
  background-color: red;
  transition: .4s;
  border-radius: 8px;
}

.uni_controls label input:checked+slider {
  background-color: white;
}

.uni_controls label input:focus+slider {
  box-shadow: 0 0 1px pink;
}

.uni_controls label input:checked+slider:before {
  transform: translateX(115px);
}

slider:after {
  content: 'OFF';
  color: black;
  display: block;
  position: absolute;
  transform: translate(-50%, -50%);
  top: 50%;
  left: 50%;
  font-size: 10px;
  font-family: Verdana, sans-serif;
}

.uni_controls label input:checked+slider:after {
  content: 'ON';
}
<div class="uni_controls">
  <input placeholder="THIS IS TEST TB" />
  <label>
    <input type="checkbox">
    <slider>
  </label>
  <input placeholder="THIS IS TEST TB" />
  <input placeholder="THIS IS TEST TB" />
  <label>
    <input type="checkbox">
    <slider>
  </label>
  <label>
    <input type="checkbox">
    <slider>
  </label>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...