简体中文
line-height 属性用于设置多行文本的间距。
| Web | Android | iOS | HarmonyOS | HarmonyOS(Vapor) |
|---|---|---|---|---|
| 4.0 | 3.9 | 4.11 | 4.61 | 5.0 |
line-height: normal | <number> | <length> | <percentage>;
| 名称 | 兼容性 | 描述 |
|---|---|---|
| normal | web平台由浏览器实现,通常约为 1.2,这取决于元素的 font-family。 |
| 平台 | 默认值 |
|---|---|
| uvue | 1.2 |
注意:W3C 默认值为:normal
HBuilderX5.0开始调整 uvue 默认值为 normal,HBuilderX5.0以下版本默认值为 1.2em。
示例为hello uni-app x alpha分支,与最新HBuilderX Alpha版同步。与最新正式版同步的master分支示例另见
示例
<template>
<view style="flex-grow: 1;">
<view style="height: 500px;background-color: gray;justify-content: center;align-items: center;">
<text class="common" style="line-height: 75px;">line-height: 75px</text>
<text class="line-height-3 common">line-height: 3</text>
<text class="common" style="line-height: 3em;">line-height: 3em</text>
<text class="common" style="line-height: 3;">line-height: 3\nline-height: 3\nline-height: 3</text>
</view>
</view>
</template>
<script>
</script>
<style>
.common {
font-size: 20px;
border: 1px red solid;
margin: 10px 0;
padding: 0 10px;
}
.line-height-3 {
line-height: 3;
}
</style>
App平台仅支持以像素值(px)、相对像素值(rpx)和相对当前元素字体大小单位(em),em单位表示数字值乘以该元素的字体大小,无单位值时使用em,默认值为 normal(HBuilderX5.0以下版本默认值为1.2em)。
line-height 样式不支持继承,建议设置大于15%字号大小的值,以避免出现渲染异常。
不支持百分比的值
不支持设置关键字 normal 值
不支持ch、rem、ex等单位
line-height 样式支持继承,默认值为normal(大约为1.2em,取决于 font-family)。