我是靠谱客的博主 妩媚牛排,这篇文章主要介绍文字居中的css代码是什么,现在分享给大家,希望可以做个参考。

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

css 文字居中

1、文字水平居中

text-align 属性规定元素中的文本的水平对齐方式,当值为center时可实现水平居中。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style type="text/css"> div { width: 300px; height: 200px; background: palegoldenrod; text-align: center } </style> </head> <body> <div>css 水平居中了--文本文字</div> </body> </html>
登录后复制

效果图:

1.png

【推荐教程:CSS视频教程 】

2、文字垂直居中

line-height 使单行文字垂直居中

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>css 垂直居中</title> <style> .box{ width: 300px; height: 300px; background: palegoldenrod; line-height:300px; } </style> </head> <body> <div class="box">css 垂直居中了--文本文字</div> </body> </html>
登录后复制

效果图:

2.png

最后

以上就是妩媚牛排最近收集整理的关于文字居中的css代码是什么的全部内容,更多相关文字居中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(103)

评论列表共有 0 条评论

立即
投稿
返回
顶部