包装HTML标签的问题复选框

时间:2015-09-22 16:24:42

标签: html css css3

我遇到一个问题,我无法获得标签(span)以与另一个span保持联机。

我创造了一个小提琴https://jsfiddle.net/0z8xvv0n/(借口风格,它们是从铬中复制出来的,用于证明这一点。

我要做的是包装标签,但保留span旁边的标签,而不是代表复选框。我没有包括:悬停或检查样式,但不会对结果产生影响

<div class="wcontrol">
    <div class=" wcheckbox-container form-group">
        <div class=" wcheckbox ">
            <input type="checkbox">
            <label class=""><span class="wcheckbox-box"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></span><span class="wcheckbox-label">This is a long check box label yeah, this is long and wont wrap properly?</span>
            </label>
        </div>
    </div>
</div>

enter image description here

很明显,我正在使用自定义HTML复选框,并使用隐藏的复选框输入来保存值。

我有什么想法可以轻松解决这个问题?

TIA

3 个答案:

答案 0 :(得分:1)

删除float: left上的display: block.wcheckbox-label

这样文本自然会在复选框旁边流动。

小提琴:https://jsfiddle.net/0z8xvv0n/6/

答案 1 :(得分:1)

我认为这可能会对您有所帮助:

删除float: left并将display: table-cell添加到 .wcheckbox-label。同时将display: table-cell添加到 .wcheckbox-box

&#13;
&#13;
.wcontrol {
    -webkit-user-select: none;
    box-sizing: border-box;
    color: rgb(72, 72, 72);
    display: block;
    font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 14px;
    height: auto;
    line-height: 20px;
    margin-bottom: 10px;
    width: auto;
}
.wcheckbox-container {
    -webkit-user-select: none;
    box-sizing: border-box;
    color: rgb(72, 72, 72);
    display: block;
    font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 14px;
    height: auto;
    line-height: 20px;
    margin-bottom: 15px;
    width: auto;
}
.wselect {
    -webkit-user-select: none;
    box-sizing: border-box;
    color: rgb(72, 72, 72);
    display: block;
    font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 14px;
    height: auto;
    line-height: 20px;
    width: auto;
}
input {

    -webkit-appearance: checkbox;
    -webkit-rtl-ordering: logical;
    -webkit-user-select: text;
    background-color: rgba(0, 0, 0, 0);
    border-bottom-color: rgb(72, 72, 72);
    border-bottom-style: none;
    border-bottom-width: 0px;
    border-image-outset: 0px;
    border-image-repeat: stretch;
    border-image-slice: 100%;
    border-image-source: none;
    border-image-width: 1;
    border-left-color: rgb(72, 72, 72);
    border-left-style: none;
    border-left-width: 0px;
    border-right-color: rgb(72, 72, 72);
    border-right-style: none;
    border-right-width: 0px;
    border-top-color: rgb(72, 72, 72);
    border-top-style: none;
    border-top-width: 0px;
    box-sizing: border-box;
    color: rgb(72, 72, 72);
    cursor: auto;
    display: block;
    font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 14px;
    font-stretch: normal;
    font-style: normal;
    font-variant: normal;
    font-weight: normal;
    height: 13px;
    left: -3000px;
    letter-spacing: normal;
    line-height: normal;
    margin-bottom: 0px;
    margin-left: 0px;
    margin-right: 0px;
    margin-top: 4px;
    padding-bottom: 0px;
    padding-left: 0px;
    padding-right: 0px;
    padding-top: 0px;
    position: absolute;
    text-align: start;
    text-indent: 0px;
    text-rendering: auto;
    text-shadow: none;
    text-transform: none;
    width: 13px;
    word-spacing: 0px;
    writing-mode: lr-tb;
    -webkit-writing-mode: horizontal-tb;
}
label {
    -webkit-user-select: none;
    box-sizing: border-box;
    color: rgb(72, 72, 72);
    cursor: pointer;
    display: inline-block;
    font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 14px;
    font-weight: normal;
    height: auto;
    line-height: 20px;
    margin-bottom: 5px;
    max-width: 100%;
    width: auto;
}
.wcheckbox-box {
    -webkit-user-select: none;
    border-bottom-color: rgb(205, 126, 115);
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
    border-bottom-style: solid;
    border-bottom-width: 3px;
    border-image-outset: 0px;
    border-image-repeat: stretch;
    border-image-slice: 100%;
    border-image-source: none;
    border-image-width: 1;
    border-left-color: rgb(205, 126, 115);
    border-left-style: solid;
    border-left-width: 3px;
    border-right-color: rgb(205, 126, 115);
    border-right-style: solid;
    border-right-width: 3px;
    border-top-color: rgb(205, 126, 115);
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    border-top-style: solid;
    border-top-width: 3px;
    box-sizing: border-box;
    color: rgb(72, 72, 72);
    cursor: pointer;
    display: table-cell; /*CHANGED*/
    float: left;
    font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 14px;
    font-weight: normal;
    height: 22px;
    line-height: 20px;
    width: 22px;

}
.wcheckbox-label {
        border:1px solid red;
    -webkit-user-select: none;
    box-sizing: border-box;
    color: rgb(72, 72, 72);
    cursor: pointer;
    display: table-cell; /*CHANGED*/
    /*float: left; REMOVED */
    font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 14px;
    font-weight: normal;
    height: auto;
    line-height: 22.4px;
    padding-left: 5.6px;
    width: auto;
}
&#13;
<div class="wcontrol">
    <div class=" wcheckbox-container form-group">
        <div class=" wcheckbox ">
            <input type="checkbox">
            <label class="">
                <span class="wcheckbox-box">
                    <span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
                </span> 
                <span class="wcheckbox-label">
                    This is a long check box label yeah, this is long and wont wrap properly?
                </span>
            </label>
        </div>
    </div>
</div>
&#13;
&#13;
&#13;

FIDDLE : DEMO

答案 2 :(得分:0)

您只需对CSS进行一些调整即可。我在下面的代码片段中添加了一些注释,可以进一步解释。

.wcontrol {
    -webkit-user-select: none;
    box-sizing: border-box;
    color: rgb(72, 72, 72);
    display: block;
    font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 14px;
    height: auto;
    line-height: 20px;
    margin-bottom: 10px;
    width: auto;
}
.wcheckbox-container {
    -webkit-user-select: none;
    box-sizing: border-box;
    color: rgb(72, 72, 72);
    display: block;
    font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 14px;
    height: auto;
    line-height: 20px;
    margin-bottom: 15px;
    width: auto;
}
.wselect {
    -webkit-user-select: none;
    box-sizing: border-box;
    color: rgb(72, 72, 72);
    display: block;
    font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 14px;
    height: auto;
    line-height: 20px;
    width: auto;
}
input {
    -webkit-appearance: checkbox;
    -webkit-rtl-ordering: logical;
    -webkit-user-select: text;
    background-color: rgba(0, 0, 0, 0);
    border-bottom-color: rgb(72, 72, 72);
    border-bottom-style: none;
    border-bottom-width: 0px;
    border-image-outset: 0px;
    border-image-repeat: stretch;
    border-image-slice: 100%;
    border-image-source: none;
    border-image-width: 1;
    border-left-color: rgb(72, 72, 72);
    border-left-style: none;
    border-left-width: 0px;
    border-right-color: rgb(72, 72, 72);
    border-right-style: none;
    border-right-width: 0px;
    border-top-color: rgb(72, 72, 72);
    border-top-style: none;
    border-top-width: 0px;
    box-sizing: border-box;
    color: rgb(72, 72, 72);
    cursor: auto;
    display: block;
    font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 14px;
    font-stretch: normal;
    font-style: normal;
    font-variant: normal;
    font-weight: normal;
    height: 13px;
    left: -3000px;
    letter-spacing: normal;
    line-height: normal;
    margin-bottom: 0px;
    margin-left: 0px;
    margin-right: 0px;
    margin-top: 4px;
    padding-bottom: 0px;
    padding-left: 0px;
    padding-right: 0px;
    padding-top: 0px;
    position: absolute;
    text-align: start;
    text-indent: 0px;
    text-rendering: auto;
    text-shadow: none;
    text-transform: none;
    width: 13px;
    word-spacing: 0px;
    writing-mode: lr-tb;
    -webkit-writing-mode: horizontal-tb;
}
label {
    -webkit-user-select: none;
    box-sizing: border-box;
    color: rgb(72, 72, 72);
    cursor: pointer;
    display: inline-block;
    font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 14px;
    font-weight: normal;
    height: auto;
    line-height: 20px;
    margin-bottom: 5px;
    max-width: 100%;
    width: auto;
}
.wcheckbox-box {
    -webkit-user-select: none;
    border-bottom-color: rgb(205, 126, 115);
    border-bottom-left-radius: 5px;
    border-bottom-right-radius: 5px;
    border-bottom-style: solid;
    border-bottom-width: 3px;
    border-image-outset: 0px;
    border-image-repeat: stretch;
    border-image-slice: 100%;
    border-image-source: none;
    border-image-width: 1;
    border-left-color: rgb(205, 126, 115);
    border-left-style: solid;
    border-left-width: 3px;
    border-right-color: rgb(205, 126, 115);
    border-right-style: solid;
    border-right-width: 3px;
    border-top-color: rgb(205, 126, 115);
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    border-top-style: solid;
    border-top-width: 3px;
    box-sizing: border-box;
    color: rgb(72, 72, 72);
    cursor: pointer;
    /* display: block;
    float: left; */ /* don't need these */
    display: inline-block; /* this preserves the explicitly set dimensions whilst allowing .wcheckbox-label to wrap around it  */
    vertical-align: middle; /* align to the middle of .wcheckbox-label */
    font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 14px;
    font-weight: normal;
    height: 22px;
    line-height: 20px;
    width: 22px;
}
.wcheckbox-label {
    -webkit-user-select: none;
    box-sizing: border-box;
    color: rgb(72, 72, 72);
    cursor: pointer;
    /* display: block;
    float: left; */ /* remove these to make the span default to inline */
    vertical-align: middle; /* align to the middle of .wcheckbox-box */
    font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: 14px;
    font-weight: normal;
    height: auto;
    line-height: 22.4px;
    padding-left: 5.6px;
    width: auto;
}
<div class="wcontrol">
    <div class=" wcheckbox-container form-group">
        <div class=" wcheckbox ">
            <input type="checkbox">
            <label class=""><span class="wcheckbox-box"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span></span><span class="wcheckbox-label">This is a long check box label yeah, this is long and wont wrap properly? This is a long check box label yeah, this is long and wont wrap properly? This is a long check box label yeah, this is long and wont wrap properly? This is a long check box label yeah, this is long and wont wrap properly?</span>
            </label>
        </div>
    </div>
</div>

相关问题