【问题标题】:checkbox forced on new line复选框强制换行
【发布时间】:2020-03-22 02:23:09
【问题描述】:

我正在尝试添加一个复选框,但它似乎总是在下一行。

我以某种方式通过设计修复了它,但它总是回到新行。

这是我从网上复制的示例复选框

input[type=checkbox]+label {
  display: block;
  cursor: pointer;
  padding: 0.2em;
  width: 113px;
}

input[type=checkbox] {
  display: none;
}

input[type=checkbox]+label:before {
  content: "\2714";
  border: 0.1em solid #000;
  border-radius: 0.2em;
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: bottom;
  color: transparent;
  transition: .2s;
}

input[type=checkbox]+label:active:before {
  transform: scale(0);
}

input[type=checkbox]:checked+label:before {
  background-color: MediumSeaGreen;
  border-color: MediumSeaGreen;
  color: #fff;
}
<input type="checkbox" id="fruit1" name="fruit-1" value="Apple">
<label for="fruit1">Apple</label>
<input type="checkbox" id="fruit2" name="fruit-2" value="Banana" disabled>
<label for="fruit2">Banana</label>
<input type="checkbox" id="fruit3" name="fruit-3" value="Cherry" checked disabled>
<label for="fruit3">Cherry</label>
<input type="checkbox" id="fruit4" name="fruit-4" value="Strawberry">
<label for="fruit4">Strawberry</label>

【问题讨论】:

  • 我给你做了一个sn-p。它没有显示您提到的行为
  • 为什么不将复选框包裹在标签中?

标签: javascript html css


【解决方案1】:

标签不要使用显示块:

<!DOCTYPE html>
<html>

<head>
    <title>Parcel Sandbox</title>
    <meta charset="UTF-8" />
    <style>
    input[type=checkbox]+label {
  cursor: pointer;
  padding: 0.2em;
  width: 113px;
}

input[type=checkbox] {
  display: none;
}

input[type=checkbox]+label:before {
  content: "\2714";
  border: 0.1em solid #000;
  border-radius: 0.2em;
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: bottom;
  color: transparent;
  transition: .2s;
}

input[type=checkbox]+label:active:before {
  transform: scale(0);
}

input[type=checkbox]:checked+label:before {
  background-color: MediumSeaGreen;
  border-color: MediumSeaGreen;
  color: #fff;
}
    </style>
</head>

<body>
    <div id="app">
        <input type="checkbox" id="fruit1" name="fruit-1" value="Apple">
        <label for="fruit1">Apple</label>
        <input type="checkbox" id="fruit2" name="fruit-2" value="Banana" disabled>
        <label for="fruit2">Banana</label>
        <input type="checkbox" id="fruit3" name="fruit-3" value="Cherry" checked disabled>
        <label for="fruit3">Cherry</label>
        <input type="checkbox" id="fruit4" name="fruit-4" value="Strawberry">
        <label for="fruit4">Strawberry</label>
    </div>
    </script>
</body>

</html>

Sample

【讨论】:

  • 先生,如果您也能帮助我解决我之前发布的问题,我将不胜感激。
  • 你指的是哪个问题,请提供链接。
  • 看起来你正在使用 .net 来渲染 DOM,不幸的是我不是 .net 专家
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-02-12
  • 2015-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多