别再滥用 line-height 了

本文详细介绍了CSS中line-height属性的应用原则,包括其在块级元素和内联元素中的使用限制,以及为什么不应该为替换内联元素设置行高。
部署运行你感兴趣的模型镜像

1) line-height 不能用在无 inline 元素的 block 元素内;

2) line-height "有继承性", 对 block 元素使用是设定内部 inline 元素的最小高度来的;

3) 不要给 "替换内联元素" 设置 line-height ,这是很不友好的行为(虽然 img 也算替换行内元素,但是给他设置没用,因为人家规范本来就不允许给替换内联元素加这玩意);

根据 MDN 上的 reference 总结,以后有的话还会加上.


您可能感兴趣的与本文相关的镜像

EmotiVoice

EmotiVoice

AI应用

EmotiVoice是由网易有道AI算法团队开源的一块国产TTS语音合成引擎,支持中英文双语,包含2000多种不同的音色,以及特色的情感合成功能,支持合成包含快乐、兴奋、悲伤、愤怒等广泛情感的语音。

!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ width: 500px; height: 500px; border:2px solid rgb(59, 59, 59); background-color: rgb(239, 239, 239); border-radius: 5px; box-shadow: 5px 5px 5px rgb(54, 34, 34); position: relative; margin:0 auto; } .line{ display: flex; overflow: hidden; } .xiaoyan{ background-image: url(../img(不用管)/刘晓燕.webp); width: 100px; height: 100px; background-size: cover; background-repeat: no-repeat; border-radius: 50%; margin-right: 30px; } .sentence{ width: 200px; height: 40px; border: 2px solid rgba(212, 212, 212, 0.635); background-color: #bababa; margin-top: 35px; line-height: 40px; color: white; } .house{ width: 200px; height: 200px; background-color:rgb(255, 220, 220); box-shadow: 10px 10px 10px rgb(54, 34, 34); position: absolute; top: 43.3%; left: 50%; transform: translate(-50%,-50%); font-size: 30px; line-height: 200px; text-align: center; } audio{ margin-top: 30px; } .hututu{ background-image: url(../img(不用管)/胡图图.webp); background-size: cover; background-repeat: no-repeat; width: 200px; height: 200px; z-index: 2; } .box{ /* 填充代码 */ } </style> </head> <body> <div class="line"> <div class="xiaoyan"></div> <div class="sentence">回家吧!</div> <audio src="../audio(不用管)/回家吧.mp3" autoplay controls></audio> </div> <div class="box"> <div class="hututu"></div> </div> <div class="house">家</div> </body> </html>完成box{ /* 填充代码 */ }这串代码使得页面中胡图图的照片覆盖在家那个方框上
06-28
<template> <div class="container" v-loading="loading"> <!-- 搜索条件卡片 --> <div class="card"> <div class="card-title">搜索条件</div> <div class="search-item"> <div class="input-wrapper"> <span class="icon">🔍</span> <input class="search-input" placeholder="产品货号" type="text" v-model="productCode" /> </div> </div> <div class="search-item"> <div class="input-wrapper"> <span class="icon">🔍</span> <input class="search-input" placeholder="组织名称" type="text" v-model="orgName" /> </div> </div> <div class="search-item"> <div class="input-wrapper"> <span class="icon">🔍</span> <input class="search-input" placeholder="仓库名称" type="text" v-model="warehouseName" /> </div> </div> </div> <!-- 操作按钮 --> <div class="card"> <div class="button-container"> <button class="btn query-btn" @click="submitData">🔍 查询</button> <button class="btn clear-btn" @click="onClear">🧹 清空</button> </div> </div> <!-- 弹窗组件 --> <DataModal :visible.sync="showDialog" :dataList="resultList" /> </div> </template> <script> import DataModal from "./DataModal.vue"; export default { name: "StockSearch", components: { DataModal }, data() { return { productCode: "", orgName: "", warehouseName: "", resultList: [], showDialog: false, loading: false }; }, mounted() { let meta = document.querySelector('meta[name="viewport"]'); if (!meta) { meta = document.createElement("meta"); meta.name = "viewport"; meta.content = "width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"; document.head.appendChild(meta); } }, methods: { onClear() { this.productCode = ""; this.orgName = ""; this.warehouseName = ""; }, async submitData() { this.loading = true; if (!this.productCode && !this.orgName && !this.warehouseName) { this.$message({ message: "请至少输入一个查询条件", type: "warning" }); this.loading = false; return; } const param = [ { type: "Map", name: "syncArg", value: { objectData: { productCode: this.productCode, warehouseName: this.warehouseName, orgName: this.orgName } } } ]; FxUI.userDefine .call_controller("CstmCtrl_B2xed__c", param) .then((res) => { if (!res) return (this.loading = false); const code = res.Value.functionResult.code; if (code != 1) { this.$alert("接口请求失败,请联系管理员!", "错误提示", { confirmButtonText: "确定", type: "error" }); this.loading = false; return; } this.resultList = res.Value.functionResult.data; this.showDialog = true; }) .catch(() => { this.$alert("请求错误,请联系管理员处理", "错误提示", { confirmButtonText: "确定", type: "error" }); }) .finally(() => { this.loading = false; }); } } }; </script> <style scoped> .container { min-height: 100vh; padding: 16px; background-color: #f5f5f5; box-sizing: border-box; } .card { background-color: #fff; padding: 16px; margin-bottom: 16px; border-radius: 8px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); /* 新增关键样式 */ min-height: auto; /* 确保高度自适应 */ display: flex; flex-direction: column; gap: 16px; /* 使用gap替代margin-bottom,更可靠 */ } .card-title { font-weight: bold; margin-bottom: 0; /* 改用gap控制间距 */ font-size: 16px; /* 明确字体大小 */ line-height: 1.4; } .search-item { /* 移除原来的 margin-bottom: 12px; */ /* 改用父容器的gap控制间距 */ min-height: 44px; /* 为触摸操作提供足够高度 */ } .input-wrapper { display: flex; align-items: center; border: 1px solid #ddd; border-radius: 6px; padding: 12px; /* 增加内边距,提供更好的触摸区域 */ background-color: #fafafa; min-height: 44px; /* 标准的触摸目标高度 */ box-sizing: border-box; } .icon { margin-right: 8px; font-size: 16px; /* 明确图标大小 */ } .search-input { flex: 1; border: none; outline: none; background: transparent; font-size: 14px; line-height: 1.4; /* 明确行高 */ min-height: 20px; /* 确保输入框有最小高度 */ } .button-container { display: flex; gap: 12px; justify-content: center; flex-wrap: nowrap; /* 确保按钮在一行显示 */ } .btn { padding: 12px 24px; /* 增加按钮内边距 */ border: none; border-radius: 6px; cursor: pointer; font-size: 14px; min-height: 44px; /* 标准触摸高度 */ flex: 1; /* 按钮平均分配宽度 */ display: flex; align-items: center; justify-content: center; gap: 8px; } .query-btn { background-color: #5a8de0; color: #fff; } .clear-btn { background-color: #f16a55; color: #fff; } .btn:active { box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3); transform: translateY(2px); } /* 针对小米手机的特定修复 */ @media screen and (-webkit-min-device-pixel-ratio: 0) { .card { gap: 16px !important; /* 强制间距 */ } .input-wrapper { min-height: 44px !important; } } /* 确保所有元素正确渲染 */ * { -webkit-tap-highlight-color: transparent; /* 移除点击高亮 */ -webkit-font-smoothing: antialiased; /* 字体抗锯齿 */ } /* 防止flex项被压缩 */ .search-item { flex-shrink: 0; } </style>
最新发布
12-04
<!-- * @Description: 海淀智慧物业平台app-通知公告 --> <template> <div class="notify_content" style="padding: 0;"> <!-- <img class="icon_img" :src="require('@/assets/img/dashboard/icon_tongzhi.png')" alt="" /> --> <div class="notice_head"> <div class="tzgg"> <img src="@/assets/img/dashboard/lingdang.png" width="20px" alt=""> 通知公告</div> <p @click="showNoticeList">更多 <a-icon type="right" /></p> </div> <van-notice-bar v-if="showUnreadModal" color="#faad14" background="#ff4d4f" class="custom-notice-bar" > <div class="leftCenterRight"> <img src="@/assets/img/image 1300.png" class="left"> <span class="modal-text">您有{{ unreadNoticeCount }}条新的通知,请查阅。</span> <!-- <van-icon name="close" class="notice-close-icon" @click="handleModalOk" /> --> <img src="@/assets/img/Group 1321322159.png" @click="handleModalOk" class="right"> <!-- <van-icon name="close" class="notice-close-icon" @click="handleModalOk" /> --> </div> </van-notice-bar> <van-pull-refresh v-model="refreshing" @refresh="onRefresh"> <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad"> <div v-for="(item, i) of list" :key="i" class="notify_content_item" :class="{ unread: i < unreadNoticeCount }" @click="notifyGoPage(item)"> <div> <p class="title">{{ item.noticeName }}</p> <p class="content ellipsis" v-html="item.noticeContent"></p> <van-divider v-if="i < list.length - 1" /> </div> <img src="item.src" alt="" v-if="false" /> </div> </van-list> </van-pull-refresh> </div> </template> <script> import rolemixins from '@/utils/rolemixins'; import { loginTest, queryNoticePublishPageList, ygNoticeList, selectNoticeList, selectNoticeCount } from '@/api/home'; export default { name: 'notifyContent', mixins: [rolemixins], data() { return { showUnreadModal: false, unreadNotice: null, unreadNoticeCount: 0, // 新增字段:未读通知数量 pathStr: this.$route.path, pathName: this.$route.meta.title ? this.$route.meta.title : '', query: { pageNo: 1, // 分页 pageSize: 10 // 每页个数 }, loading: false, finished: false, refreshing: false, list: [] }; }, created() { this.selectNoticeList(); this.checkUnreadNotice(); }, activated() { }, mounted() { // this.onRefresh() }, methods: { // 更多按钮跳转至公告列表 showNoticeList() { this.$router.push('/noticeListAll'); }, //查询公告列表页 // selectNoticeList() { // this.query.userId = JSON.parse(localStorage.getItem('userInfo')).id; // selectNoticeList(this.query).then((res) => { // if (res.success && undefined != res.result) { // this.list = res.result.records.slice(0, 3); // } else { // this.list = [{ // noticeName: '暂无公告', // noticeContent: '暂无公告' // }]; // } // }); // }, // 查询通知列表 selectNoticeList() { const userId = JSON.parse(localStorage.getItem('userInfo')).id; this.query.userId = userId; selectNoticeList(this.query).then(res => { if (res.success && res.result?.records) { this.list = res.result.records.slice(0, 3); } else { this.list = [{ noticeName: '暂无公告', noticeContent: '暂无公告' }]; } }); }, // 检查是否有未读通知 checkUnreadNotice() { const userId = JSON.parse(localStorage.getItem('userInfo')).id; selectNoticeCount({ userId }).then(res => { if (res.success && res.result > 0) { this.unreadNoticeCount = res.result this.showUnreadModal = true; } }); }, // 弹窗确认后跳转详情页 handleModalOk() { this.showUnreadModal = false; const userId = JSON.parse(localStorage.getItem('userInfo')).id; selectNoticeList({ userId, isRead: false }).then(res => { if (res.success && res.result.records.length > 0) { const firstUnread = res.result.records[0]; this.$router.push({ path: '/issueNoticeDetail', query: { projectId: firstUnread.projectId, id: firstUnread.id, item: item } }); } }); }, ygNoticeList() { var param = { pageNo: this.query.pageNo, pageSize: this.query.pageSize }; ygNoticeList(param).then((res) => { if (res.success) { this.list = res.result.records; } else { this.list = []; } }); }, onLoad() { if (this.refreshing) { this.list = []; this.refreshing = false; } this.loading = true; this.query.pageNo++; this.getList(); }, onRefresh() { this.query.pageNo = 0; //起始为第一页 this.list = []; this.refreshing = true; this.finished = false; //加载与不加载的状态 setTimeout(() => { this.loading = true; //下拉刷新状态 this.onLoad(); //刷新成功调用列表方法 this.loading = false; }, 1000); }, getList() { this.loading = false; let data = Object.assign({}, this.query); selectNoticeList(data).then(res => { if (res.success) { this.list = [...this.list, ...res.result.records]; this.loading = false; if (this.list.length >= res.result.total) { this.finished = true; } } }); // queryCollectDataList(data).then(res => { // if (res) { // this.total = res.result.total; // res.result.records.map(item => { // this.list.push(item); // }); // this.loading = false; // if (this.list.length >= res.result.total) { // this.finished = true; // } // } // }); }, notifyGoPage(item) { this.$router.push({ path: '/issueNoticeDetail', query: { projectId: item.projectId, id: item.id, item: item } }); }, goPage() { } } }; </script> <style scoped lang="less"> @import '@/assets/css/comm.less'; @bg-color: #ff4d4f; // 红色背景 @text-color: white; @icon-size: 40px; // 图标大小 @close-icon-size: 14.16px; // 关闭图标大小 @close-margin-right: 20px; // 右边距 .notify_content { width: 350px; min-height: 198px; margin: 10px auto; background: #fff; border-radius: 7px 7px 25px 7px; position: relative; overflow-y: auto; // 自定义 van-notice-bar 样式 .custom-notice-bar { border-radius: 20px; width: 350px; height: 24px; position: fixed; top: 156px; .leftCenterRight{ display: flex; justify-content: center; align-items: center; text-align: center; .left{ margin-left: 23px; margin-right: 21px; } .right{ margin-left: 103px; } } .modal-text { line-height: @icon-size + 25px; font-size: 12px; color: @text-color; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .notice-close-icon { background-color: #FF920A !important; width: @close-icon-size; height: @close-icon-size; font-size: @close-icon-size; margin-left: 125px; margin-right: @close-margin-right; color: @text-color; cursor: pointer; line-height: @icon-size + 25px; } img{ width: 14.16px; height: 14.16px; } } .custom-modal{ background-color: red; } .notice_head { display: flex; justify-content: space-between; align-items: center; border-bottom: #E3E3E3 1px solid; padding: 12px; .tzgg { color: #000000; font-family: "PingFang SC"; font-size: 15px; font-style: normal; font-weight: 700; line-height: normal; } p { color: #3b77b3; font-size: 14px; font-weight: 600; } } .modal-content { font-size: 16px; color: #333; text-align: center; } .icon_img { position: absolute; top: 1px; right: 10px; width: 35px; } .notify_content_item { display: flex; padding-left: 12px; margin: 10px; border-radius: 12px; border: 1px solid #def0fe; background: linear-gradient(to right, #eaf6ff, #ffffff); >div { // width: calc(100% - 100px); width: calc(100% - 20px); padding-right: 15px; p { margin: 10px 0; } .van-divider { border:none } p.title { font-family: PingFangSC, PingFang SC; font-weight: 600; font-size: 15px; color: blue; } p.content { font-family: PingFangSC, PingFang SC; font-weight: 400; font-size: 0.4rem; color: red; // width: calc(100% - 20px); } } &.unread { background: linear-gradient(260deg, #FFF 5.08%, #FCE4E9 90.46%); border-color: #ff4d4f; .content { color: #F88600; } } img { width: 100px; height: 60px; margin-bottom: 10px; } } } </style> 为什么接口返回的数据<p class="content ellipsis" v-html="item.noticeContent"></p>这段代码第一条数据字体比其他的大
08-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值