Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何在已设置样式的复选框右侧对齐标签_Html_Css - Fatal编程技术网

Html 如何在已设置样式的复选框右侧对齐标签

Html 如何在已设置样式的复选框右侧对齐标签,html,css,Html,Css,我正在努力将标签与我的样式化复选框对齐。我正在使用。我有以下HTML: <label> <input id="test" class="cmn-toggle cmn-toggle-round" type="checkbox" /> <label for="test"></label> testlabel </label> 结果将标签中的文本直接放置在复选框的下方,而不是其右侧。以下是一个屏幕截图作为示例: 我的问题很简单

我正在努力将标签与我的样式化复选框对齐。我正在使用。我有以下HTML:

<label>
  <input id="test" class="cmn-toggle cmn-toggle-round" type="checkbox" />
  <label for="test"></label>
  testlabel
</label>
结果将标签中的文本直接放置在复选框的下方,而不是其右侧。以下是一个屏幕截图作为示例:


我的问题很简单。为什么会这样?如何将标签排列在复选框的右侧?

您的文本标签被推到切换下方,因为它被设置为“显示:块”。你可以: 1.将此更改为display:inline block,这将使内联文本在其右侧的旁边向上显示。 2.保留display:block,但将float:left添加到切换中,以便文本显示在其旁边


您只需根据需要在文本中添加边距/填充;您可能希望将其包装在一个或其他元素中,以便更轻松地设置其样式

将float:left添加到我的切换中,可以在一行中有多个切换时提供一些有趣的行为。是的,那是可能发生的。如果您发布了您的实际代码,这会有所帮助,但只要看看它,我认为如果每个标签对(切换和文本)都包装在它们自己的块级元素(如div)中,那么应该可以防止这种情况发生。如果希望切换及其标签都水平显示在一行中,则需要将每对的包装器元素设置为
float:left
以及.Right。把每一个单独包装在一个小盒子里会有帮助。我很好奇为什么会有不同,但很高兴有了一个解决方案。这困扰了我几个小时:)谢谢,这是因为文本标签的高度比切换高度短。当您将一个元素设置为“浮动:左”时,它将“浮动”到周围元素允许的最上方/最左侧。由于文本标签没有切换所占的垂直空间大,因此后续切换将向上推到上一个文本标签上,然后向左推,并撞到上一个切换,从而产生交错效果。将文本标签/切换对包装在一个div中可确保两者的高度相同,因此您不再有空间让后续元素紧贴。完美,这很有意义。因此,div将其垫出,这样后续切换就不会浮到它上面。谢谢你的奖金信息!
input.cmn-toggle-round + label {
  padding: 2px;
  width: 60px;
  height: 30px;
  background-color: #dddddd;
  -webkit-border-radius: 30px;
  -moz-border-radius: 30px;
  -ms-border-radius: 30px;
  -o-border-radius: 30px;
  border-radius: 30px;
}
input.cmn-toggle-round + label:before, input.cmn-toggle-round + label:after {
  display: block;
  position: absolute;
  top: 1px;
  left: 1px;
  bottom: 1px;
  content: "";
}
input.cmn-toggle-round + label:before {
  right: 1px;
  background-color: #f1f1f1;
  -webkit-border-radius: 30px;
  -moz-border-radius: 30px;
  -ms-border-radius: 30px;
  -o-border-radius: 30px;
  border-radius: 30px;
  -webkit-transition: background 0.4s;
  -moz-transition: background 0.4s;
  -o-transition: background 0.4s;
  transition: background 0.4s;
}
input.cmn-toggle-round + label:after {
  width: 29px;
  background-color: #fff;
  -webkit-border-radius: 100%;
  -moz-border-radius: 100%;
  -ms-border-radius: 100%;
  -o-border-radius: 100%;
  border-radius: 100%;
  -webkit-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  -moz-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  -webkit-transition: margin 0.4s;
  -moz-transition: margin 0.4s;
  -o-transition: margin 0.4s;
  transition: margin 0.4s;
}
input.cmn-toggle-round:checked + label:before {
  background-color: #8ce196;
}
input.cmn-toggle-round:checked + label:after {
  margin-left: 30px;
}