css div 文字水平上下居中

<html>
    <head>
    	<style type="text/css">
    		#d1{
    			border: 1px solid purple;
    			width: 100px;
    			height: 100px;
    			line-height: 100px; 
    			text-align: center;
    		}
    	
    	</style>
    </head> 

    <body>
    	
    	<div id="d1">
    		一个区域A
    	</div>

    </body>

</html>

如果不写line-height,那就只是水平居中。

line-height必须和 height值一致。

因此如果要水平上下居中必须要有三个属性,height line-height text-align

    原文作者:小菜911
    原文地址: https://blog.csdn.net/carl_jiang/article/details/76579628
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞