在 CSS 中设置行高
cssweb developmentfront end technology更新于 2025/1/7 0:12:17
行高可以通过 CSS 的 line-height 属性定义。该属性仅接受正值。
语法
CSS line-height 属性的语法如下 −
Selector {
line-height: /*value*/
}
示例
以下示例说明了 CSS line-height 属性。
<!DOCTYPE html>
<html>
<head>
<style>
div * {
margin: 1.5em;
box-shadow: -13px -10px 10px 1px crimson;
}
#demo {
line-height: 60%;
}
p {
box-shadow: 13px -10px 10px 1px grey;
line-height: 50px;
}
</style>
</head>
<body>
<h2>Demo Heading</h2>
<div>
<p>This is demo text one.</p>
<div>This is demo text two.</div>
<div id="demo">This is demo text three.</div>
</div>
</body>
</html>
输出
这将给出以下输出 −

示例
<!DOCTYPE html>
<html>
<head>
<style>
div * {
margin: auto;
padding: 3em;
}
p {
height: 100px;
width: 100px;
border: thin solid;
border-radius: 50%;
box-shadow: 0 20px 10px 1px grey;
line-height: 0.6;
}
</style>
</head>
<body>
<h2>What is C#?</h2>
<div>
<p>C# is a strongly-typed language. Every variable and constant has a type, as does every expression that evaluates to a value.</p>
</div>
</body>
</html>
输出
这将给出以下输出 −

相关文章
有用资源
css 参考教程 - 该教程包含有关 css 的更多信息:https://www.cainiaomax.com/css/

