在自定义复选框中居中选中/勾选

Ben*_*ats 3 html css checkbox styling

我正在构建一个自定义复选框,功能已基本完成,但样式还有很长的路要走。

我有几个问题,

  1. 我需要支票位于圆圈中心
  2. 我只需要在单击复选框本身而不是文本时激活检查。

恐怕如果不使用左侧位置的左侧填充,我似乎无法将支票居中。

超文本标记语言

<label for='product-45-45'>
  <input type='checkbox' style="float:left;" id='product-45-45' />
  <div class="accord-text">
    <strong>header:</strong> sub text
    <strong>more text!</strong>
  </div>
</label>
Run Code Online (Sandbox Code Playgroud)

CSS

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

input[type=checkbox] + .accord-text:before {
  width: 30px;
  height: 30px;
  border-radius: 200%;
  background-color: #d6e4ec;
  border: 1px solid #000;
  display: block;
  font-size: 150%;
  font-weight: 900;
  content: "";
  color: green;
}

input[type=checkbox]:checked + .accord-text:before {
  display: table;
  content: "\2713";
}
Run Code Online (Sandbox Code Playgroud)

Fac*_*cca 5

  • 问题1:text-align: center;当复选框ic被选中时,并style="float:left;"从复选框中删除
  • 问题2:把div中的文本去掉accord-text,放到外面。

.row{
  display: flex;
  flex-direction: row;
}

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

input[type=checkbox] + .accord-text:before {
  width: 30px;
  height: 30px;
  border-radius: 200%;
  background-color: #d6e4ec;
  border: 1px solid #000;
  display: block;
  font-size: 140%;
  font-weight: 900;
  content: "";
  color: green;
}

input[type=checkbox]:checked + .accord-text:before {
  display: table;
  content: "\2713";
  text-align: center;
}
Run Code Online (Sandbox Code Playgroud)
<div class="row">
  <label for='product-45-45'>
  <input type='checkbox' style="float:left;" id='product-45-45' />
  <div class="accord-text">

  </div>
</label>

  <strong>header:</strong> sub text
  <strong>more text!</strong>
</div>
Run Code Online (Sandbox Code Playgroud)