jQuery Mobile 中的居中元素
jQuery Mobile 框架是否有一种使元素(特别是按钮)居中的方法?看起来它默认将所有内容左对齐,但我找不到方法(在框架内)来做到这一点。
Does the jQuery Mobile framework have a way of centering elements, specifically buttons? It looks like it defaults to left-aligning everything and I can't find a way (within the framework) to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
这些答案都不适合我。我必须把它们结合起来。 (也许是因为我使用的是“按钮”标签,而不是作为按钮输入的链接?)
在 HTML 中:
在 CSS 中:
None of these answers alone worked for me. I had to combine them. (Maybe it is because I'm using a "button" tag and not a link typed as a button?)
In the HTML:
In the CSS:
您可以将按钮设为锚元素,并将其放入具有以下属性的段落中:
为我工作。
You can make the button an anchor element, and put it in a paragraph with the attribute:
Worked for me.
要使它们正确居中并且仅适用于包装器 .center-wrapper 内的项目,请使用此功能。 (所有选项组合起来应该可以跨浏览器工作)如果没有,请在此处发表回复!
To have them centered correctly and only for the items inside the wrapper .center-wrapper use this. ( all options combined should work cross browser ) if not please post a reply here!
这适用于
HTML
Css
This works
HTML
Css
根据您的要求进行调整
Adjust as your requirement
jQuery Mobile 似乎没有一个 css 类来居中元素(我搜索了它的 css)。
但您可以编写自己的附加 css。
尝试创建您自己的:
示例 HTML:
并看看会发生什么。您可能需要将文本对齐设置为包装标签的中心,这样可能效果更好:
示例 HTML:
jQuery Mobile doesn't seem to have a css class to center elements (I searched through its css).
But you can write your own additional css.
Try creating your own:
example HTML:
and see what happens. You might need to set text-align to center in the wrapping tag, so this might work better:
example HTML:
一种矫枉过正的方法:在 div 中的内联 css 中做到了这一点:
像魅力一样中心!
An overkill approach: in inline css in the div did the trick:
Centers like a charm!
在您不打算反复使用它的情况下(即样式表中不需要),内联样式语句通常可以在样式表中的任何地方使用。例如:
In the situation where you are NOT going to use this over and over (i.e. not needed in your style sheet), inline style statements usually work anywhere they would work inyour style sheet. E.g:
最好的选择是将任何您想要居中的元素放在
div
中,如下所示:和 css 或内联样式:
The best option would be to put any element you want to be centered in a
div
like this:and css or inline style:
我发现这里提到的其他一些方法存在问题。另一种方法是使用布局网格 B,并将内容放入块 b 中,并将块 a 和 c 留空。
http://demos.jquerymobile.com/1.1.2/docs /content/content-grids.html
I had found problems with some of the other methods mentioned here. Another way to do it would be to use layout grid B, and put your content in block b, and leave blocks a and c empty.
http://demos.jquerymobile.com/1.1.2/docs/content/content-grids.html