本教程操作环境: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>
登录后复制
效果图:
【推荐教程: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>
登录后复制
效果图:
最后
以上就是妩媚牛排最近收集整理的关于文字居中的css代码是什么的全部内容,更多相关文字居中内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复