css 如何在开关旁边垂直居中文本?[副本]

qv7cva1a  于 2023-06-25  发布在  其他
关注(0)|答案(1)|浏览(142)

此问题已在此处有答案

How can I vertically align elements in a div?(28回答)
7天前关闭
我想做一个文本在“切换标签”类中心垂直与“开关”,但我失败了这里是我使用的代码

.toggle-label {
  font-weight: bold;
  font-size: 20px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 54px;
  height: 28px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-round {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
  border-radius: 34px;
}

.slider-round:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
  border-radius: 50%;
}

.switch input:checked+.slider-round {
  background-color: #e53f71;
}

.switch input:focus+.slider-round {
  box-shadow: 0 0 1px #e53f71;
}

.switch input:checked+.slider-round:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}
<span class="toggle-label">BGM</span>
<label class="switch" style="margin-right: 20px;">
     <input type="checkbox" id="bgm" checked>
     <span class="slider-round"></span>
</label>
<span class="toggle-label">SFX</span>
     <label class="switch">
     <input type="checkbox" id="sfx" checked>
<span class="slider-round"></span>
</label>

我试着设置切换标签的顶部填充,但它仍然不工作,请帮助我使切换标签中心垂直与开关

9vw9lbht

9vw9lbht1#

试试加

  • 垂直对齐:中间;*

.toggle-label.switch
这样他们就可以扯平了。

相关问题