本文主要是介绍CSS设置单行文字水平垂直居中的方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>单行文字水平垂直居中</title><style>div {/* 给div设置宽高 */width: 400px;height: 200px;margin: 100px auto;background-color: red;/* 设置行高为盒子的高度 */line-height: 200px;/* 设置文字水平居中 */text-align: center;}</style>
</head>
<body><div>我是要水平垂直居中的文字</div>
</body>
</html>
效果图:
这篇关于CSS设置单行文字水平垂直居中的方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!