如何将两个除法元素设置为平行



我想使标签和复选框大小相同。我可以问一下如何针对此类问题更改CSS属性吗?

屏幕截图显示了这个问题。

[![复选框和标签][1]][1]


const viewTemplate = (
<div className="stack-small">
<div className="c-cb">
<input
id={props.id}
type="checkbox"
defaultChecked={props.completed}
onChange={() => props.toggleTaskCompleted(props.id)}
/>
<label className="todo-label" htmlFor={props.id}>
<p style={{ fontWeight: props.important ? 'bold' : 'normal' }}>{props.name}</p>
</label>
</div>

CSS

.c-cb {
box-sizing: border-box;
font-family: Arial, sans-serif;
-webkit-font-smoothing: antialiased;
font-weight: 400;
font-size: 1.6rem;
line-height: 1.25;
display: block;
position: relative;
min-height: 44px;
padding-left: 40px;
clear: left;
}
.c-cb > label::before,
.c-cb > input[type="checkbox"] {
box-sizing: border-box;
top: -2px;
left: -2px;
width: 44px;
height: 44px;
display: inline-block;
}
.c-cb > input[type="checkbox"] {
-webkit-font-smoothing: antialiased;
cursor: pointer;
position: absolute;
z-index: 1;
margin: 0;
opacity: 0;
display: inline-block;
}
.c-cb > label {
font-size: inherit;
font-family: inherit;
line-height: inherit;
display: inline-block;
margin-bottom: 0;
padding: 8px 15px 5px;
cursor: pointer;
touch-action: manipulation;
}
.c-cb > label::before {
content: "";
position: absolute;
border: 2px solid currentColor;
background: transparent;
}
.c-cb > input[type="checkbox"]:focus + label::before {
border-width: 4px;
outline: 2px  #228bec;
}
.c-cb > label::after {
box-sizing: content-box;
content: "";
position: absolute;
top: 11px;
left: 9px;
width: 18px;
height: 7px;
transform: rotate(-45deg);
border: solid;
border-width: 0 0 5px 5px;
border-top-color: transparent;
opacity: 0;
background: transparent;
}
.c-cb > input[type="checkbox"]:checked + label::after {
opacity: 1;
}

有没有什么CSS框架需要安装才能解决这些问题?[1] :https://i.stack.imgur.com/ZTQtn.gif

  • 使用CSSflexalign-items: center;justify-content: center;来对齐子元素
  • 使用<label>作为包装。切勿将块级元素(DIV、P、H1等(放置在内联级元素(如标签、span等等(内

/*QuickReset*/ * {margin:0;box-sizing:border-box;}
body {font:14px/1.4 sans-serif;}
/* CUSTOM-CHECKBOX */
.c-cb-label {
font-size: 1.6em;
display: flex; align-items: center;
cursor: pointer;
}
.c-cb-label::before {
content: " ";
display: flex; align-items: center; justify-content: center;
width: 1.5em; height: 1.5em;
margin-right: 0.3em;
border: 4px solid currentColor;
}
.c-cb :checked + .c-cb-label::before {
content: "2714"; /* or use a font-icon (like icomoon) unicode hex */
}
<label class="c-cb">
<input hidden type="checkbox" name="test" />
<span class="c-cb-label">Prop name</span>
</label>

最新更新