繁体   English   中英

垂直居中标题文本

[英]vertically center header text

我正在寻找增加jquery移动应用程序标头的大小。 当我这样做时,我需要将标题居中。 我发现我可以添加如下行:

        line-height: 30px; 

到css,但这远非骇客所能及。 我认为必须有更好的方法来做到这一点。

<!DOCTYPE html>
<html>
    <head>
        <title>Page Title</title>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css" />
        <script src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js"></script>
        <style type="text/css"><!--
            .ui-header {
                height: 50px;                
            }
            -->
        </style>  
    </head>
    <body>
        <div data-role="page">
            <div data-role="header">
                <h1>This Needs To Be Centred Vertically</h1>
            </div>

            <div data-role="content">
                <p>Page content goes here.</p>   
            </div>

            <div data-role="footer">
                <h4>Page Footer</h4>
            </div>
        </div>
    </body>
</html>

使块元素的文本垂直居中的最简单方法是使行高与该元素的高度相同。 请注意,这仅在一行文本时才有效。

line-height: 30px;
height: 30px;

在内联或表单元格元素上,可以使用vertical-align: middle获得相同的效果。

还要注意,在IE6-7中,强制display: table-cell元素上的display: table-cell无效。

在您的情况下,我建议您使用line-height / height技术。

您可以尝试这样的事情:

<div data-role="header">
   <div class="ui-bar">
      <h1>This Needs To Be Centred Vertically</h1>
   </div>
</div>

Doc: http : //jquerymobile.com/test/docs/toolbars/docs-headers.html

您可以尝试

display: table-cell; 
vertical-align: middle;

在您的CSS中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM