html - 切换输入和输入不是内联的

标签 html css

我已经尝试让它工作了一段时间,但我似乎无法让它工作。请有人帮忙。 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>

最佳答案

只需将 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>

关于html - 切换输入和输入不是内联的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50024173/

相关文章:

java - 使用java将文本文件中的信息输入到网页上

javascript - 使用向下/向上滑动过渡动画 v-if (Vue.js 2)

html - 为什么 favicon 图标不显示在 Firebug 网络面板中

javascript - 在javascript中触发按钮点击?

css - 如何从 Sass mixin 输出 CSS 计数器

html - CSS 阻止 div 高度超出视口(viewport)+滚动时使 topnav 保持不变

javascript - 将 2 个表单操作合并为一个表单

css - CSS 选择器可以解决行高问题吗?

javascript - 需要在 Bootstrap 折叠目标卡中切换 bg-dark

html - 如何通过最大宽度限制 div,但在较小时保持内部元素的宽度?