html - 在复选框 css 之后对齐标签内容

标签 html css checkbox

我从 this source 中设置了 Checkbox 的样式如下:

.toggle-button {
    margin: 0 20px;
}


/*
   * Toggle button styles
   */

.toggle-button {
    position: relative;
    display: inline-block;
    color: rgb(80, 77, 77);
}

.toggle-button label {
    display: inline-block;
    cursor: pointer;
    text-align: left;
}

.toggle-button input {
    display: none;
}

.toggle-button__icon {
    cursor: pointer;
    pointer-events: none;
}

.toggle-button__icon:before,
.toggle-button__icon:after {
    content: "";
    position: absolute;
    top: 45%;
    left: 35%;
    transition: 0.2s ease-out;
}

.toggle-button--tuli label {
    line-height: 20px;
    text-indent: 30px;
}

.toggle-button--tuli input[type=checkbox]:checked~.toggle-button__icon {
    background: #fff;
}

.toggle-button--tuli input[type=checkbox]:checked~.toggle-button__icon:before,
.toggle-button--tuli input[type=checkbox]:checked~.toggle-button__icon:after {
    opacity: 1;
}

.toggle-button--tuli .toggle-button__icon {
    position: absolute;
    top: 0;
    left: 0;
    width: 20px;
    height: 20px;
    transition: all 0.2s;
    border: 2px solid rgb(37, 146, 236);
    border-radius: 1px;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
}

.toggle-button--tuli .toggle-button__icon:before,
.toggle-button--tuli .toggle-button__icon:after {
    top: 5px;
    left: 2px;
    width: 12px;
    height: 2px;
    border-radius: 3px;
    background: #fff;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
    top: 35%;
    background: #0175b2;
    opacity: 0;
    transform-origin: left center;
}

.toggle-button--tuli .toggle-button__icon:before {
    transform: translate(0, 0) rotate(45deg) scale(0.6, 1);
}

.toggle-button--tuli .toggle-button__icon:after {
    transform: translate(4px, 6px) rotate(-45deg);
}

.toggle-button--tuli:hover input[type=checkbox]:not(:checked)~.toggle-button__icon {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


<div class="toggle-button toggle-button--tuli">
  <input id="toggleButton11" type="checkbox">
  <label for="toggleButton11">I confirm that I have read and agree to the <a href="#" style="color:#2c6ed7">Terms of Use</a> specified by the client and some long text to continue with to show the alignment below checkbox</label>
  <div class="toggle-button__icon"></div>
</div>

如果您运行代码片段,您会看到当标签内容换行时,它会出现在复选框下方。如何修改 css 以对齐标签内容以显示在复选框之后。我试过 text-indent 但这只适用于第一行。希望能得到一些帮助。

最佳答案

使用 padding-left 代替 text-indent,它会如您所愿地工作:

.toggle-button {
    margin: 0 20px;
}


/*
   * Toggle button styles
   */

.toggle-button {
    position: relative;
    display: inline-block;
    color: rgb(80, 77, 77);
}

.toggle-button label {
    display: inline-block;
    cursor: pointer;
    text-align: left;
}

.toggle-button input {
    display: none;
}

.toggle-button__icon {
    cursor: pointer;
    pointer-events: none;
}

.toggle-button__icon:before,
.toggle-button__icon:after {
    content: "";
    position: absolute;
    top: 45%;
    left: 35%;
    transition: 0.2s ease-out;
}

.toggle-button--tuli label {
    line-height: 20px;
    padding-left: 30px;
}

.toggle-button--tuli input[type=checkbox]:checked~.toggle-button__icon {
    background: #fff;
}

.toggle-button--tuli input[type=checkbox]:checked~.toggle-button__icon:before,
.toggle-button--tuli input[type=checkbox]:checked~.toggle-button__icon:after {
    opacity: 1;
}

.toggle-button--tuli .toggle-button__icon {
    position: absolute;
    top: 0;
    left: 0;
    width: 20px;
    height: 20px;
    transition: all 0.2s;
    border: 2px solid rgb(37, 146, 236);
    border-radius: 1px;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
}

.toggle-button--tuli .toggle-button__icon:before,
.toggle-button--tuli .toggle-button__icon:after {
    top: 5px;
    left: 2px;
    width: 12px;
    height: 2px;
    border-radius: 3px;
    background: #fff;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
    top: 35%;
    background: #0175b2;
    opacity: 0;
    transform-origin: left center;
}

.toggle-button--tuli .toggle-button__icon:before {
    transform: translate(0, 0) rotate(45deg) scale(0.6, 1);
}

.toggle-button--tuli .toggle-button__icon:after {
    transform: translate(4px, 6px) rotate(-45deg);
}

.toggle-button--tuli:hover input[type=checkbox]:not(:checked)~.toggle-button__icon {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


<div class="toggle-button toggle-button--tuli">
  <input id="toggleButton11" type="checkbox">
  <label for="toggleButton11">I confirm that I have read and agree to the <a href="#" style="color:#2c6ed7">Terms of Use</a> specified by the client and some long text to continue with to show the alignment below checkbox</label>
  <div class="toggle-button__icon"></div>
</div>

关于html - 在复选框 css 之后对齐标签内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47767863/

相关文章:

html - 将嵌套元素 w.r.t 定位到它的直接父元素

html - 垂直显示复选框,每个复选框旁边都有标签

html 文本输入和复选框。 CSS 问题

javascript - 使用完整路径获取文件对象

javascript - JQuery 可拖动元素在 droppable.append(draggable) 上消失在 droppable 中

html - 如何在选择中删除悬停时的蓝色突出显示,选项输入 html for chrome

javascript - 如何使用ajax或jquery在选中和取消选中时设置复选框的值

javascript - Electron :总是返回 ontouchstart = true

html - 如何将我的 div "downloads"始终放在图片下方 70px

css - 100% 高度 Div,图像在正中间 - CSS