多行预览
本课属于 Coddy Tailwind CSS 学习旅程的“响应式 UI 模式”单元。第 33 课,共 55 课。
卡片描述可能需要显示几行,而不是截断成一行标签。line-clamp-2 会将文本块限制为两行可见内容,并裁剪其余部分,同时在文档中保留完整文本。示例在预览旁提供了一个完整描述链接。
<article><p class="line-clamp-2 leading-6">A longer event description appears here.</p><a href="#details">Read the full description</a></article>根据预览的用途选择行数限制。line-clamp-3允许显示三行;line-clamp-none会移除行数限制,恢复普通的溢出显示。有更多空间时,可以使用响应式变体移除窄屏预览限制。
截断适用于摘要,不适用于隐藏重要说明或错误。要确保用户仍能访问完整内容。已知行高后,无需假设每行有多少个字符,就能轻松检查预览的预期高度。
挑战
中等将提供的描述预览限制为 3 行,保留现有的 24px 行高。保留完整文本和完整描述链接。预览必须裁剪溢出内容,而不是扩展卡片。
保留提供的内容、语义元素和 ID。编辑指定的工具类。编辑后按“运行”预览,然后按“检查”/运行代码来评测结果。提供的 JavaScript 为只读内容。
保留可用的完整描述链接,并确保其未限制行数的完整文本目标仍可访问。
亲手试试
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Interface workshop</title><link rel="stylesheet" href="./styles.css"></head><body>
<article class="w-48"><p id="summary" class="leading-6 ">A hands-on workshop explores drawing, printing, color mixing, composition and collaborative studio practice. Bring a notebook and discover several approaches with the teaching team. A hands-on workshop explores drawing, printing, color mixing, composition and collaborative studio practice. Bring a notebook and discover several approaches with the teaching team. A hands-on workshop explores drawing, printing, color mixing, composition and collaborative studio practice. Bring a notebook and discover several approaches with the teaching team. </p><a href="#full">Read full description</a></article>
<section id="full" tabindex="-1" class="mt-8"><h2>Full workshop description</h2><p id="fullText">A hands-on workshop explores drawing, printing, color mixing, composition and collaborative studio practice. Bring a notebook and discover several approaches with the teaching team. A hands-on workshop explores drawing, printing, color mixing, composition and collaborative studio practice. Bring a notebook and discover several approaches with the teaching team. A hands-on workshop explores drawing, printing, color mixing, composition and collaborative studio practice. Bring a notebook and discover several approaches with the teaching team. </p></section></body></html>
这节课包含一个小测验。开始学习即可作答,并记录你的进度。