html怎样使文字居中


本文摘自PHP中文网,作者藏色散人,侵删。

html使文字居中的方法:1、通过“text-align:center;”属性设置文字水平居中;2、通过“line-height:height;”属性设置文字垂直居中。

本文操作环境:windows7系统、HTML5&&CSS3版、Dell G3电脑。

html文字居中代码具体示例如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

<!DOCTYPE HTML>

<html>

<head>

 <title>html文字居中测试</title>

 <meta charset="UTF-8">

 <style type="text/css">

 body{background: #ddd;}

 div{width:300px;height:180px;margin:10px auto;color:#fff;font-size:24px;}

 .box1{background: #71a879;text-align: center;}

 .box2{background: #6a8bbc;line-height: 200px;}

 .box3{background: #dea46b;text-align: center;line-height: 200px;}

 </style>

</head>

<body>

<div >html文字水平居中</div>

<div >html文字垂直居中</div>

<div >html文字水平上下居中</div>

</body>

</html>

以上代码效果在本地测试如下图:

阅读剩余部分

相关阅读 >>

Html如何设置字体文字的倾斜效果?(代码详解)

Html页面如何显示上标和下标

Html header标签怎么用

Html <br>与<p>标签区别

Html的<frame>标签

Html怎么设置超链接颜色

Html怎么设置背景色

Html如何进行页面注释

如何在Html中插入空格

Html关于结构语义化的问题

更多相关阅读请进入《Html》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...