当前位置:Gxlcms > html代码 > 关于padding设置的问题_html/css_WEB-ITnose

关于padding设置的问题_html/css_WEB-ITnose

时间:2021-07-01 10:21:17 帮助过:22人阅读

如果我给定了元素框的高度,padding似乎没那么好用了。
比如:





这是文字


如果不加height:50px;这句,文字在红色框里就是居中对齐的,加了这句,文字在框里就偏上。为什么?不是说padding给一个值可以让四边都对称的吗? 如果我一定要设定框高度,那么用什么办法实现文字在空间里居中?


回复讨论(解决方案)

a
{display:block;
background-color:red;
width:120px;
height:50px;
line-height:50px;
text-align:center;
padding:6px;
text-decoration:none;
}

人气教程排行