文字居中 的css代码是“text-align: center ;”或“line-h ei ght:值;”。text-align属性规定元素文本的水平对齐方式,当值为center时,即可实现水平居中;而设置line-height可实现文字垂直居中。
本教程操作环境:windows7系统、CSS3 && HT ML 5版、Dell G3 电 脑。
css 文字居中
1、文字水平居中
text-align 属性规定元素中的文本的水平对齐方式,当值为center时可实现水平居中。
<!DOCTY PE html>
<html>
<head>
< ;m eta 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 使单行文字垂直居中
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<t IT le>css 垂直居中</title>
<style>
.box{
width: 300px;
height: 300px;
background: palegoldenrod;
line-height:300px;
}
</style>
</head>
<body>
<div class="box">css 垂直居中了--文本文字</div>
</body>
</html>效果图:
更多编程相关知识,请访问:编程视频!!
以上就是文字居中的css代码 是什么 的详细内容,更多请关注其它相关 文章 !
总结
以上是 为你收集整理的 文字居中的css代码是什么 全部内容,希望文章能够帮你解决 文字居中的css代码是什么 所遇到的问题。
如果觉得 网站内容还不错, 推荐好友。
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did199464