答案:通过line-height设置行高,推荐使用无单位数值以实现响应式;通过margin-bottom控制段落间距,优先使用rem单位;结合媒体查询与相对单位可优雅适配不同屏幕尺寸,保持文本可读性与布局协调性。<p>
<p>CSS中调整文字行高主要通过line-height
margin
margin-bottom
margin-top
line-height
margin
line-height
line-height
line-height: 1.5;
font-size
font-size
line-height
font-size
line-height: 1.5
px
line-height: 24px;
%
line-height: 150%;
font-size
150%
1.5
em
rem
line-height: 1.5em;
line-height: 1.5rem;
em
font-size
rem
html
font-size
margin
margin
<p>
margin-bottom
margin-bottom
p { margin-bottom: 1em; }em
rem
px
margin-top
margin-top
margin-bottom
margin
margin: 0 0 1em 0;
margin-bottom
line-height
margin
line-height
line-height
line-height: 1.5;
font-size
px
px
line-height
line-height
line-height: 1;
1.5
1.6
margin
margin
padding
padding-bottom
padding
padding-bottom
padding
padding
gap
gap
p
display: flex; flex-direction: column;
gap: 1em;
1em
margin
text-indent
word-spacing
letter-spacing
margin
gap
padding
line-height
1.5
1.6
font-size
font-size
line-height
line-height
line-height
margin-bottom
em
rem
em
font-size
rem
html
font-size
rem
html
font-size
16px
rem
html
font-size
rem
/* 基础设置 */
html {
font-size: 16px; /* 默认基准 */
}
body {
font-size: 1rem; /* 16px */
line-height: 1.6;
}
p {
margin-bottom: 1.5rem; /* 24px */
}
h1 {
font-size: 2.5rem; /* 40px */
line-height: 1.2;
margin-bottom: 1rem;
}
/* 小屏幕优化 */
@media (max-width: 768px) {
html {
font-size: 14px; /* 小屏幕上字体和间距都相应缩小 */
}
h1 {
font-size: 2rem; /* 28px */
}
p {
margin-bottom: 1rem; /* 14px */
}
}
/* 大屏幕优化 */
@media (min-width: 1200px) {
html {
font-size: 18px; /* 大屏幕上字体和间距都相应放大 */
}
h1 {
font-size: 3rem; /* 54px */
}
p {
margin-bottom: 2rem; /* 36px */
}
}html
font-size
rem
clamp()
font-size: clamp(1rem, 2vw + 1rem, 2.5rem);
line-height
em
rem
margin
以上就是CSS行距怎么设置_CSS调整文字行高与段落间距教程的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号