我需要为我的switch 主题按钮制作背景,但我陷入了这部分

How it should be ->

How i did so far ->

这是我在switch 主题按钮部分中的代码

<div class="themeContainer">
      <p>calc</p>
      <div>
        <span class="themeText">THEME</span>
        <span class="btnContainer">
          <button id="switchTheme1">1</button>
          <button id="switchTheme2">2</button>
          <button id="switchTheme3">3</button>
        </span>
      </div>
    </div>

首先,我制作了一个跨度容器,这样其他元素就不会 break line ,但由于跨度自然地以内联方式显示,我无法更改它的高度.

之后,我try 将btnContainer更改为显示:inline-Block;但没有起作用

现在我有点迷失了,如果有人能在这件事上帮助我,我会很感激.

.themeContainer {
   color: hsl(0, 0%, 100%);
   width: 535px; 
   height: 40px;
   display: flex;
   justify-content: space-between;
   align-items: center;
}

.themeContainer p {
    font-size: 30px;
    margin-left: 10px;
}

.themeContainer .btnContainer {
    background-color:hsl(224, 36%, 15%);
    border-radius: 50%;
}

.themeContainer .themeText {
    font-size: 12px;
    margin-right: 10px;
}

.themeContainer button {
    color: hsl(0, 0%, 100%);
    background-color:hsl(224, 36%, 15%);
    font-size: 12px;
    max-width: 50px;
    max-height: 50px;
    width: 20px;
    height: 20px;
    margin: -1px;
    border-radius: 50%;
    border-style: none;
    cursor: pointer;
}

推荐答案

您可以进行一些最终调整.但我编辑了THIS CODEPEN个以满足您的需要.

.tw-toggle {
  background: #252D44;
  display: inline-block;
  padding: 2px 3px;
  border-radius: 20px;
  position: relative;
  border: 2px solid #95A5A6;
}

.tw-toggle label {
  text-align: center;
  font-family: sans-serif;
  display: inline-block;
  color: #95A5A6;
  position: relative;
  z-index: 2;
  margin: 0;
  text-align: center;
  padding: 2px 3px;
  font-size: 20px;
  margin: 5px
  /* cursor: pointer; */
}

.tw-toggle input {
  /* display: none; */
  position: absolute;
  z-index: 3;
  opacity: 0;
  cursor: pointer;
  height: 30px;
  width: 30px;
}

.tw-toggle span {
  height: 30px;
  width: 30px;
  line-height: 21px;
  border-radius: 50%;
  background: #fff;
  display: block;
  position: absolute;
  left: 15px;
  top: 2px;
  transition: all 0.3s ease-in-out;
}

.tw-toggle input[value="false"]:checked~span {
  background: rgb(249, 107, 89);
  left: 2px;
  top: 5px;
  color: #fff;
}

.tw-toggle input[value="true"]:checked~span {
  background: rgb(249, 107, 89);
  left: 64px;
  top: 5px;
  color: #fff;
}

.tw-toggle input[value="-1"]:checked~span {
  background: rgb(249, 107, 89);
  left: 33px;
  top: 5px;
  color: #fff;
}

.tw-toggle input[value="false"]:checked+label,
.tw-toggle input[value="true"]:checked+label {
  color: #fff;
}

.tw-toggle input[value="-1"]:checked+label {
  color: #fff;
}
<div class="tw-toggle">
  <input type="radio" name="toggle" value="false">
  <label class="toggle toggle-yes">1</label>
  <input checked type="radio" name="toggle" value="-1">
  <label class="toggle toggle-yes">2</label>
  <input type="radio" name="toggle" value="true">
  <label class="toggle toggle-yes">3</label>
  <span></span>
</div>

Another iteration个更接近您的原始版本可能是:

.tw-toggle {
  background: #252D44;
  display: inline-block;
  padding: 2px 3px;
  border-radius: 20px;
  position: relative;
  border: 2px solid #95A5A6;
}

.tw-toggle label {
  text-align: center;
  font-family: sans-serif;
  display: inline-block;
  color: #95A5A6;
  position: relative;
  z-index: 2;
  margin: 0;
  text-align: center;
  padding: 2px 3px;
  font-size: 20px;
  margin: 5px
  /* cursor: pointer; */
}

.tw-toggle input {
  /* display: none; */
  position: absolute;
  z-index: 3;
  opacity: 0;
  cursor: pointer;
  height: 30px;
  width: 30px;
}

.tw-toggle span {
  height: 30px;
  width: 30px;
  line-height: 21px;
  border-radius: 50%;
  background: #fff;
  display: block;
  position: absolute;
  left: 15px;
  top: 2px;
  transition: all 0.3s ease-in-out;
}

.tw-toggle input[value="false"]:checked~span {
  background: rgb(249, 107, 89);
  left: 3px;
  top: 5px;
  color: #fff;
}

.tw-toggle input[value="true"]:checked~span {
  background: rgb(249, 107, 89);
  left: 64px;
  top: 5px;
  color: #fff;
}

.tw-toggle input[value="-1"]:checked~span {
  background: rgb(249, 107, 89);
  left: 33px;
  top: 5px;
  color: #fff;
}

.tw-toggle input[value="false"]:checked+label,
.tw-toggle input[value="true"]:checked+label {
  color: #fff;
}

.tw-toggle input[value="-1"]:checked+label {
  color: #fff;
}
<div style="padding:0 15px; width:70px; display: flex;
    justify-content: space-between; font-weight:bold;">
  <div>
    1
  </div>
  <div>
    2
  </div>
  <div>
    3
  </div>
</div>
<div class="tw-toggle">
  <input type="radio" name="toggle" value="false">
  <label class="toggle toggle-yes">&nbsp&nbsp</label>
  <input checked type="radio" name="toggle" value="-1">
  <label class="toggle toggle-yes">&nbsp&nbsp</label>
  <input type="radio" name="toggle" value="true">
  <label class="toggle toggle-yes">&nbsp&nbsp</label>
  <span></span>
</div>

Html相关问答推荐

角|将动态html属性添加到子组件

如何在angular 17.2中使用routerLink解决此错误

在FlexBox中将div拉伸到父div的完全高度

悬停效果在新西兰表上不起作用

Firefox和Chrome在文字装饰和文字阴影方面的不同优先顺序

轨道上的居中范围滑块拇指(Webkit)

Bootstrap 5.3.2模式页脚左填充还是左边距?

div居中碰撞问题

悬停表格单元格文本时,使元素的字体大小更大,同时保持表格单元格的高度不变

在移动屏幕上显示时分支树视图的响应能力问题

并排放置两个 div,同时 div2 环绕 div1

Django 如何从文件系统下载文件?

如何使用CSS Select 同级元素的::before伪元素?

从垫分页器中删除输入边框

如何截断一些文本并用双引号引起来?

透明渐变凹矩形

悬停一个 div 时更改所有其他 div 上的字体 colored颜色

在 React (NEXT) 中,当我try 进行动态补充时,我无法使用实例this来引用输入

嵌套固定定位的 Div 滚动条渗透到前景中的 Div

有没有办法在 CSS 类子句中指定多个 HTML 元素?