html - 在 jQuery Mobile 中对齐复选框和文本输入的问题

标签 html css jquery-mobile

我不能用这个。它可能很简单,但我无法让复选框与其各自的文本输入并排水平对齐。

这是 fiddle

HTML

<fieldset data-role="controlgroup">
<div data-role="fieldcontain" style="float:left; width:100%">
    <input type="checkbox" name="1" id="1" value="1" />
    <input type="text" name="name" id="basic1" value="A" />
</div>
<div data-role="fieldcontain" style="float: left; width:100%">
    <input type="checkbox" name="2" id="2" value="2" />
    <input type="text" name="name" id="basic2" value="B" />
</div>
<div data-role="fieldcontain" style="float: left; width:100%">
    <input type="checkbox" name="3" id="3" value="3" />
    <input type="text" name="name" id="basic3" value="C" />
</div>
<div data-role="fieldcontain" style="float: left; width:100%">
    <input type="checkbox" name="3" id="4" value="4" />
    <input type="text" name="name" id="basic4" value="D" />
</div>
</fieldset>

我也尝试过使用网格:

<div class="ui-grid-a">
<div class="ui-block-a">
    <input type="checkbox" name="jobtype" id="1a" value="1" />
</div>
<div class="ui-block-b">
    <input type="text" name="name" id="basic1a" value="A" />
</div>

CSS

.ui-input-text {
width: 80%;
float:right;
display:inline
}
.ui-block-a {
width:20%
}
.ui-block-b {
width:80%;
}

我在这里错过了什么?谢谢!

最佳答案

要让 jQM 增强复选框,请用标签包围输入元素:

<div>
    <div data-role="controlgroup" style="float:left; width:100%">
        <label><input type="checkbox" name="jobtype" id="1" value="1" /></label>
        <input type="text" name="name" id="basic1" value="A" />
    </div>
    <div data-role="fieldcontain" style="float: left; width:100%">
        <label><input type="checkbox" name="jobtype" id="2" value="2" /></label>
        <input type="text" name="name" id="basic2" value="B" />
    </div>
    <div data-role="fieldcontain" style="float: left; width:100%">
        <label><input type="checkbox" name="jobtype" id="3" value="3" /></label>
        <input type="text" name="name" id="basic3" value="C" />
    </div>
</div>

然后排列并平衡高度:

.ui-checkbox {
    width: 19%;
    float:left;
    display:inline;
    margin-top: 8px !important;  
}
.ui-checkbox label {    
  height: 12.2px;  
}
.ui-input-text {
    width: 80%;
    float:right;
    display:inline
} 

DEMO

您也可以使用 ListView 来做到这一点:

    <div class="container">
        <ul data-role="listview" class="has-checkDiv">
            <li>
                <div>
                    <input type="text" name="name1" id="basic1" value="A" />
                </div>
                <div class="checkDiv">
                    <input type="checkbox" name="jobtype" id="1a" value="1" />
                </div>
            </li>
            <li>
                <div>
                    <input type="text" name="name2" id="basic2" value="B" />
                </div>
                <div class="checkDiv">
                    <input type="checkbox" name="jobtype" id="1b" value="1" />
                </div>
            </li>
        </ul>
    </div>

.container {
    padding-top: 12px;
}

.has-checkDiv > li > div:first-child {
    margin-left: 40px !important;
}
.checkDiv {
    position: absolute;
    top: 0px;
    left: 0px;
    width: 40px;
    bottom: 0px;
    z-index: 100;
}
.checkDiv .ui-checkbox {
    position: absolute;
    top: 50%;
    left: 20px;
    height: 22px;
    width: 22px;
    margin: 0;
    margin-top: -11px;
    margin-left: -11px;
}

DEMO

关于html - 在 jQuery Mobile 中对齐复选框和文本输入的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33815431/

相关文章:

html - 为什么边框会增加元素的宽度?

javascript - 不同body背景onClick之间如何过渡? (尝试 2)

css - 响应式列表布局,带有内部没有固定元素的元素的填充

javascript - 移动滚动方向检测溢出 : hidden page

HTML- 内容在 IE 中无法正确呈现,否则它在 FF/chrome 中工作得很好

html - CSS:更改代码中上一个div的高度

javascript - 我如何通过使用 javascript 将 jQuery Mobile 样式保留在按钮等上注入(inject)到 HTML 中?

javascript - Mobile Safari 滚动到底部以加载更多内容,例如 Facebook

javascript - 错误 : Can't bind to 'ngModel' since it isn't a known property of

jquery - 将图像放置在 div 的右上角