首页 > 开发 > CSS > 正文

关于css中line-height(行高)设置无效的问题的解决方法

2024-07-11 08:31:31
字体:
来源:转载
供稿:网友

关于css中line-height(行高)设置无效的问题

我们先写下这一串代码:

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> .head{ height: 100px; text-align: center; line-height: 100px;/* 设置行高,让字体居中 */ background: #333;/* 设置整个背景为黑色,便于观察字体 */ color: red; font:700 18px simsun;/* 对字体进行设置 */ } </style></head><body> <div class="head"> 你好,西南石油大学。 </div></body></html>

然后在浏览器中打开看看效果:

我们发现在垂直方向,字体并没有在盒子的中间显示。

然后我们把设置行高那条语句放在设置字体(font)的下面:

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> .head{ height: 100px; text-align: center; background: #333;/* 设置整个背景为黑色,便于观察字体 */ color: red; font:700 18px simsun;/* 对字体进行设置 */ line-height: 100px;/* 设置行高 */ } </style></head><body> <div class="head"> 你好,西南石油大学。 </div></body></html>

然后用浏览器打开:

字体就成功地跳到中间去啦~~~~~

总结:在用css对行高进行设置时,line-height的属性必须在font的下面,否则无效!

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持错新站长站。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表