我希望文本 Hello World 位于页面中心
这是我的代码,但不起作用:
<html>
<head>
<style type="text/css">
body { text-align: center; }
</style>
</head>
<body>
<center>Hello world</center>
</body>
</html>
我不想使用 div 标签
我希望文本 Hello World 位于页面中心
这是我的代码,但不起作用:
<html>
<head>
<style type="text/css">
body { text-align: center; }
</style>
</head>
<body>
<center>Hello world</center>
</body>
</html>
我不想使用 div 标签
试试这个:
<html>
<head>
<style type="text/css">
body { text-align: center; margin-top:50%; }
p{margin:auto;
color:blue;}
</style>
</head>
<body>
<p>Hello world</p>
</body>
</html>
尝试这样的事情
HTML
<html style="width:100%;height:100%">
<body style="width:100%;height:100%">
<table cellpadding="0" cellspacing="0" width="100%" height="100%">
<tr>
<td align="center" valign="middle" width="100%" height="100%">
<p>Hello world</p>
</td>
</tr>
</table>
</body>
</html>
演示:http: //jsfiddle.net/enve/8MEwY/2/
将文本对齐到中心很容易,只需使用:
<html>
<head>
</head>
<body>
<p style="text-align:center">Hello world</p>
</body>
</html>
您可以在没有解决方案的情况下尝试这样<table>
,但我不确定当您向页面添加更多样式时它是否会起作用。
<html>
<head>
<style type="text/css">
p {
margin-top: 25%;
text-align: center;
color: blue;
}
</style>
</head>
<body>
<p>Hello world</p>
</body>
</html>