gpt4 book ai didi

html - 格式化文本时应该使用边距还是填充?

转载 作者:搜寻专家 更新时间:2023-10-31 22:58:25 24 4
gpt4 key购买 nike

<分区>

我正在为我的网站设计一些 CSS。我需要格式化(在标题和段落之间添加一些适当的间距)一段在单一背景上带有标题和段落的统一文本。这可以使用 margin 来完成或 padding属性(property)。我确实理解这两者在 CSS 中的区别。此外,关于这些 CSS 属性的使用,还有很多关于 SO 的问题:

但是,毫无疑问,应该使用什么属性来进行正确的文本格式设置。假设我需要像这样格式化文本:

Formatting example

我应该使用 margin 吗?或 padding控制文本元素(标题和段落)之间的间距?建议在<p>上使用什么和 <h..>标签?常见的做法是什么?

这是我现在想到的:

/* tiny reset */
html { font-size: 10px; }
html, body { margin: 0; padding: 0; }
* { box-sizing: border-box; }

p {
font-family: 'Roboto', sans-serif;
font-size: 1.6rem;
line-height: 2.5rem;
margin: 0.6rem 0 2.0rem 0;
padding: 0 2px 4px 2px;
width: 100%; /* Opera needs this */
text-rendering: optimizeLegibility;
}

h1, h2 {
font-family: 'Roboto', sans-serif;
font-weight: 700;
text-align: center;
text-transform: uppercase;
padding: 0 2px 4px 2px;
text-rendering: optimizeLegibility;
}
h1 {
font-size: 4.0rem;
line-height: 4.0rem;
margin: 2.6rem 0 2.0rem 0;
}
h2 {
font-size: 3.2rem;
line-height: 3.2rem;
margin: 2.4rem 0 2.0rem 0;
}

.wrap {
margin: 20px;
padding: 20px;
-webkit-box-shadow: 0px 0px 12px 4px rgba(0,0,0,0.3);
-moz-box-shadow: 0px 0px 12px 4px rgba(0,0,0,0.3);
box-shadow: 0px 0px 12px 4px rgba(0,0,0,0.3);
}
<div class="wrap">
<p>The last declaration of a block doesn't need to be terminated by a semi-colon, though it is often considered good style to do it as it prevents forgetting to add it when extending the block with another declaration.</p>

<h2><strong>CSS statements</strong></h2>
<p>If style sheets could only apply a declaration to each element of a Web page, they would be pretty useless. The real goal is to apply different declarations to different parts of the document.</p>
<p>CSS allows this by associating conditions with declarations blocks. Each (valid) declaration block is preceded by a selector which is a condition selecting some elements of the page. The pair selector-declarations block is called a ruleset, or often simply a rule.</p>

</div> <!-- /wrap -->

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com