Yii2 ActiveField::checkboxList 渲染歪了

Yii2 ActiveField::checkboxList rendering is crooked

有没有简单的方法来修复复选框列表的这种歪曲渲染?

此代码:

<?= $form->field($model, 'targeting_gender')->checkboxList(['Male'=>'Male','Female'=>'Female','Unknown'=>'Unknown']) ?>

最后是这样的:

问题是标签的不同长度。

这是一些 CSS 的复选框:

type="checkbox"]:not(:checked), [type="checkbox"]:checked {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
[type="checkbox"], [type="radio"] {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    padding: 0;
}

input[type="checkbox" i] {
    background-color: initial;
    cursor: default;
    appearance: checkbox;
    box-sizing: border-box;
    margin: 3px 3px 3px 4px;
    padding: initial;
    border: initial;
}

input {
    -webkit-writing-mode: horizontal-tb !important;
    text-rendering: auto;
    color: -internal-light-dark(black, white);
    letter-spacing: normal;
    word-spacing: normal;
    text-transform: none;
    text-indent: 0px;
    text-shadow: none;
    display: inline-block;
    text-align: start;
    appearance: textfield;
    background-color: -internal-light-dark(rgb(255, 255, 255), rgb(59, 59, 59));
    -webkit-rtl-ordering: logical;
    cursor: text;
    margin: 0em;
    font: 400 13.3333px Arial;
    padding: 1px 2px;
    border-width: 2px;
    border-style: inset;
    border-color: -internal-light-dark(rgb(118, 118, 118), rgb(195, 195, 195));
    border-image: initial;
}

PS: 我正在使用 materializecss

我的快速修复(因为我不是 CSS 专家)是:

<?= $form->field($model, 'targeting_gender')->checkboxList(
        ['Male'=>'Male&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;','Female'=>'Female&nbsp;&nbsp;&nbsp;','Unknown'=>'Unknown'],
        ['encode'=>false]) 
?>

这导致:

但是如果你有时间和精力,你可以在标签中添加 html-attributes 和额外的 css:

<?= $form->field($model, 'targeting_gender')->checkboxList(
        ['Male'=>'Male','Female'=>'Female','Unknown'=>'Unknown'],
        ['encode'=>false, 'itemOptions'=>['labelOptions'=>['class'=>'fixed-width-label']]]) 
?>