html - 如何使用 jQuery Mobile 构建一个 2 x 2 的按钮网格?

标签 html css jquery-mobile

我正在尝试使用以下代码在 jQuery Mobile 中构建一个 2x2 网格:

<div class="ui-grid-a">
<a class="ui-block-a" data-role="button" data-icon="arrow-r" data-iconpos="right" href="#france">France</a>
<a class="ui-block-b" data-role="button" data-icon="arrow-r" data-iconpos="right" href="#india">India</a>
<a class="ui-block-a" data-role="button" data-icon="arrow-r" data-iconpos="right" href="#uk">UK</a>
<a class="ui-block-b" data-role="button" data-icon="arrow-r" data-iconpos="right" href="#usa">USA</a>
</div>

我希望法国和印度排在第一行,英国和美国排在第二行。实际上,我在四个不同的行上设置了四个按钮,即一个在彼此之上。

我对 CSS 进行了一些试验,发现如果我将 A 元素的宽度更改为 49%,那么我每行会得到两个按钮,只是按钮不在屏幕中央(即它们只占用 2 x 49% = 98% 的屏幕空间和 2% 留在右边)。如果我强制 A 的宽度为 50%,我会得到初始行为,即每行一个按钮。

谁有解决办法?谢谢。

最佳答案

您需要将它们包装在 ui-block-? div 中,示例:

HTML

<div data-role="page" id="home">
    <div data-role="content">
        <div class="ui-grid-a">
            <div class="ui-block-a">
            <a data-role="button" data-icon="arrow-r" data-iconpos="right" href="#france">France</a>
            </div>
            <div class="ui-block-b">
            <a data-role="button" data-icon="arrow-r" data-iconpos="right" href="#india">India</a>
            </div>
            <div class="ui-block-a">
            <a data-role="button" data-icon="arrow-r" data-iconpos="right" href="#uk">UK</a>
            </div>
            <div class="ui-block-b">
            <a data-role="button" data-icon="arrow-r" data-iconpos="right" href="#usa">USA</a>
            </div>
        </div>
    </div>
</div>

关于html - 如何使用 jQuery Mobile 构建一个 2 x 2 的按钮网格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9197578/

相关文章:

javascript - pageinit 上的面板高度尺寸计算

php - 从某个页面重定向到另一个页面时如何获取引用 URL

javascript - 我怎么知道我的 Javascript 执行了?

javascript - 确定 element.style 的位置

html - CSS:如何给一个 div 加边框,将它完全放在另一个 div 中?

javascript - 带有 html css 的杂志容器

class - Jquery Mobile 强制它不使用类

javascript - 使用 Kinvey.Social 通过 Angular 应用程序和 Promise API 登录

html - 如何在 HTML 中插入分页符以便 wkhtmltopdf 解析它?

javascript - 在滚动 div 中保留 x 行数