css如何让文字在div内居中

在css中可以通过设置属性让文字在div内居中 , 今天我来给大家介绍下css如何让文字在div内居中

css如何让文字在div内居中



需要这些哦
电脑
css+html
代码编纂器(本文用的HBuilder)
方式/
1起首在编纂器里新建一个center.html , 用来进修css若何让文字在div内居中
css如何让文字在div内居中



2在body区域里 , 新建一个calss为test的div 
css如何让文字在div内居中



3在css标签中 , 给test标签写上根本属性:宽500px , 高100px , 居中显示 , 布景色为红色
css如何让文字在div内居中



4在浏览器中打开center.html , 看一下今朝的结果
css如何让文字在div内居中



5回到编纂 , 在css标签中 , 给test标签加上
text-align: center;(程度居中)
line-height: 100px;(垂直居中)
css如何让文字在div内居中



6在浏览器中打开center.html , 看一下最终结果
css如何让文字在div内居中



7贴一下代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>css若何让文字在div内居中</title>
</head>
<style>
.test{
【css如何让文字在div内居中】 width: 500px;
height: 100px;
background: red;
margin: 0 auto;
text-align: center;
line-height: 100px;
}
</style>
<body>
<div class="test">文字居中</div>
</body>
</html>

注重事项div 高度几多 , line-height后面就写几多
若是帮忙到您 , 请给个赞哦

以上内容就是css如何让文字在div内居中的内容啦 , 希望对你有所帮助哦!

    猜你喜欢