line-height:1的存在意义是什么(v1)

一、line-height:1的存在意义是什么(v1)

1. 加不加这段代码的区别是什么?

示例代码

<!DOCTYPE html>
<html lang="en">
<style>
    p{line-height:1;} /* 随时注释的line-height:1 */

    p{margin:0;background-color:#f5f5f5;border-bottom:solid 1px #ccc}
    p:nth-child(1){font-size:12px;}
    p:nth-child(2){font-size:14px;}
    p:nth-child(3){font-size:16px;}
    p:nth-child(4){font-size:18px;}
    p:nth-child(5){font-size:20px;}
</style>
<body>
    <p>12</p>
    <p>14</p>
    <p>16</p>
    <p>18</p>
    <p>20</p>
</body>
</html>

不加的情况下如下:
在这里插入图片描述
加上的情况:
在这里插入图片描述
明显的,我们可以看出它们的高度产生了变化。

也可以说文字上下的空白区域减少了,更贴合字体了。

2. 这样做的主要目的是什么?

这样做的主要目的是为了高保真还原设计图,在特意提及并有需求的情况下,部分的UI设计图要求精准控制展示效果,字体的高度是被严格控制的。

字体行高需要紧贴字体的情况下,可以使用line-height:1,或者line-height:100%。它们两个的效果是一样的。


二、参考

https://developer.mozilla.org/zh-CN/docs/Web/CSS/line-height

https://blog.51cto.com/u_15302032/5069527

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
<template> <view> <image :src="mySrc" style="width: 100%;"></image> <view class="show"> <button type="primary" @click="selectimg()">请上传户口本页面</button> </view> <view> <uni-section title="姓名" type="line"> <uni-card :is-shadow="false"> <text class="uni-body">{{personname}}</text> </uni-card> </uni-section> <uni-section title="身份证号" type="line"> <uni-card :is-shadow="false"> <text class="uni-body">6105******</text> </uni-card> </uni-section> <uni-section title="评论区" type="line" padding> <uni-easyinput type="textarea" v-model="value" placeholder="请输入内容"></uni-easyinput> </uni-section> </view> <uni-section title="评论得分" type="line" padding> <uni-rate v-model="rateValue" @change="onChange" /> </uni-section> <view> <button type="primary">确定评论</button> </view> </view> </template> <script> export default { data() { return { mySrc: require("@/static/logo/lo3.png"), personname:"", }; }, methods: { selectimg() { uni.chooseImage({ count: 1, sizeType: ['original', 'compressed'], sourceType: ['album'], success: (res) => { console.log(res.tempFilePaths[0]); this.mySrc = res.tempFilePaths[0]; this.changeImgToBase64(res.tempFilePaths[0]); } }); }, changeImgToBase64(source_img) { uni.getFileSystemManager().readFile({ filePath: source_img, encoding: "base64", success: (res) => { console.log("加密之后的图片格式:" + JSON.stringify(res)); this.makeFinalResult(res.data); }, }); }, async makeFinalResult(base64) { let token = await uni.request({ url: 'https://aip.baidubce.com/oauth/2.0/token', data: { grant_type: 'client_credentials', client_id: '2kKeVk6LvdFX8knIyYUodMDr', client_secret: '9pSXGfzvv7q1Fo76WRkeyXVpZGrj8zxb', }, success: (res) => { console.log("获取token:===>" + res.data.access_token); token = res.data.access_token; }, }); uni.request({ url: 'https://aip.baidubce.com/rest/2.0/ocr/v1/household_register?access_token=' + token, method: 'POST', data: { image: base64, }, header: { "Content-Type": "application/x-www-form-urlencoded", }, success: (res) => { console.log("最终的结果:" + JSON.stringify(res)); //this.personname = res.words_result.Name.words; }, }); }, }, }; </script> <style lang="scss"> .show { display: flex; justify-content: center; height: 100vh; align-items: center; } <style>
最新发布
07-20
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值