jQuery移动按钮对齐问题

问题描述 投票:8回答:4

我正在尝试使用jQuery Mobile,但由于它是标记驱动的框架,因此我感到有点困惑。

我创建了一个测试页面,在该页面中,我只是试图将一个按钮向右对齐,但是我无法做到这一点。我尝试了float: right,但是它不起作用。尽管margin-left通过给出特定的百分比可以工作,但是当我调整页面大小时,同样的东西却无法工作。

这里是我的Fiddle code。任何帮助都会很棒。

<div data-role="page">
    <div data-role="header" data-theme="b" data-position="fixed">
        <h1 style="font-size: 1.5em; text-align: left; margin-left: 70px;"
            data-role="none">Test</h1>
    </div>

    <div id="contentLogin" align="center" name="contentConfirmation" data-role="content">

        <p style="font-size: 0.85em; color: #000000">
            <b>Welcome to my page</b>
        </p>
        <br>
        <div class="ui-grid-b responsive">

            <div style="margin: 0px; margin-top: 0px; margin: 0px;" class="ui-block-a">

                <div data-role="fieldcontain">
                    <label for="url" class="alignleft">Username:*</label>
                    <input id="userId1" class="required" name="uid_r" placeholder="" type="text">
                </div>
                <div data-role="fieldcontain">
                    <label for="url" class="alignleft">Password:*</label>
                    <input id="Password1" class="required" name="pwd_r" value="" type="password">
                </div>
                <button id="login" data-theme="a" type="button" href="home.html" data-mini="false" data-inline="true" >Login</button>

            </div>
            <div class="ui-block-b">BLOCK A ADS</div>
            <div class="ui-block-c" style="margin-top: 0px;">
                BLOCK C
            </div>

        </div>
    </div>
    <div data-role="footer" data-theme="b" data-position="fixed">
    </div>
</div>
javascript jquery jquery-mobile
4个回答
13
投票

为什么不将按钮放在div内并右对齐div?父div内的所有内容(包括按钮)都将右对齐。

<div align="right"><button id="login" data-theme="a" type="button" href="home.html" data-mini="false" data-inline="true" >Login</button></div>

检查小提琴http://jsfiddle.net/mayooresan/96s59/2/


6
投票

使用ui-btn-right。它更容易,不那么冗长,并且(我认为)使用jquery来做事情。

<a href="#" class="ui-btn-right ui-btn-inline">Login</a>

4
投票

先前的答案是正确的,但是您应该使用CSS样式(不建议使用aling =“”)

<div style="text-align: right;">
<button data-inline="true">Login</button>
</div>

3
投票

如果想要多个按钮,您可能会遇到问题...

尝试:

<div style="float:right">
    <button data-inline="true">Login</button>
</div>

如果要有多个按钮(左右对齐)。

如果使用:

<div style="text-align: right;">
    <button data-inline="true">Login</button>
</div>

div将在任何现有按钮的下方开始一个新的块,因此左侧不能有其他图标。

Class ui-btn-icon-left|right使您可以将按钮向左|向右对齐,但是我发现将两个按钮与ui-btn-icon-right一起使用会使它们重叠。

下面的模板为我工作了两个左对齐的按钮和一个页脚中的两个右按钮:

<a href="#home" class="ui-btn">Home</a>
<a href="#intro" class="ui-btn">Intro</a>
<div style="float:right">
    <a href="#review" class="ui-btn">Review</a>
    <a href="#exit" class="ui-btn">Exit</a>
</div>  

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.