如何將開關旁邊的文字垂直居中?
P粉354948724
P粉354948724 2023-09-15 11:58:54
0
1
443

我想在“toggle-label”類中心與“switch”垂直製作一個文本,但我失敗了 這是我使用的程式碼

.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>

我嘗試設定切換標籤的頂部填充,但它仍然不起作用 請幫我讓切換標籤與開關垂直居中

P粉354948724
P粉354948724

全部回覆(1)
P粉489081732

嘗試新增

垂直對齊:中間;

#到.toggle-label.switch

這應該會讓他們彼此相處融洽。

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!