gpt4 book ai didi

html - CSS 1em 改变浏览器默认行高

转载 作者:行者123 更新时间:2023-11-28 04:04:14 25 4
gpt4 key购买 nike

我有一个 CSS 文件。使用 line-height: 1em; 属性,文本看起来像这样:

enter image description here

如果没有该属性,它看起来像这样:

enter image description here

1em 应该等于它已经存在的值,但是如果你仔细观察,你会发现它们是不同的。为什么这些显示不同?

body {
color: green;
font-family: Verdana, Arial, Geneva, Arial Black;
font-weight: normal;
background-color: #ffcf79;
font-size: 25px;
}
h1 {
text-decoration: underline;
font-size: 150%;
}
h2 {
text-decoration: underline;
font-size: 1.2em;
}
p.para1 {color: blue;}
p.para2 {color: purple;}
p.para3 {
color: purple;
font-size: 15px;
line-height: 1.5em;
background-color: #e5e4d7;
padding: 20px;
border-color: black;
border-width: 2px;
border-style: solid;
}
p.para4 {
color: black;
font-size: 15px;
line-height: 1.5em;
background-color: #e5e4d7;
padding: 20px;
border-color: black;
border-width: 2px;
border-style: solid;
margin: 20px;
margin-top: 50px;
margin-left: 400px;
}
.imagec {
display: block;
margin-left: auto;
margin-right: auto;
padding: 3px;
background-color: silver;
border-color: black;
border-style: solid;
}
<body>
<h1> The Fish Web Site </h1>
<p class="para1"> Welcome to the Fish Web Site. Everything you want to know about fish is in this web site. </p>
<img class="imagec" src="_images/barracuda.jpg">
<h2> This is a section on Bass fish </h2>
<p class="para2"> Bass fish live in lakes. The word for fish in Latin is <i>Pisces</i> </p>
<p class="para3"> A fish is any member of a paraphyletic group of organisms that consist of all gill-bearing aquatic craniate animals that lack limbs with digits. Included in this definition are the living hagfish, lampreys, and cartilaginous and bony fish, as well as various extinct related groups. Most fish are ectothermic ("cold-blooded"), allowing their body temperatures to vary as ambient temperatures change, though some of the large active swimmers like white shark and tuna can hold a higher core temperature. Fish are abundant in most bodies of water. They can be found in nearly all aquatic environments, from high mountain streams (e.g., char and gudgeon) to the abyssal and even hadal depths of the deepest oceans (e.g., gulpers and anglerfish). At 32,000 species, fish exhibit greater species diversity than any other group of vertebrates.</p>
<p class="para4"> A fish is any member of a paraphyletic group of organisms that consist of all gill-bearing aquatic craniate animals that lack limbs with digits. Included in this definition are the living hagfish, lampreys, and cartilaginous and bony fish,
as well as various extinct related groups. Most fish are ectothermic ("cold-blooded"), allowing their body temperatures to vary as ambient temperatures change, though some of the large active swimmers like white shark and tuna can hold a higher core temperature. Fish are abundant in most bodies of water. They can be found in nearly all aquatic environments, from high mountain streams (e.g., char and gudgeon) to the abyssal and even hadal depths of the deepest oceans (e.g., gulpers and anglerfish). At 32,000 species, fish exhibit greater species diversity than any other group of vertebrates.</p>
</body>

最佳答案

我看不出浏览器有 1em 的默认行高的原因,因为在大多数情况下,两行之间没有空格只会导致可读性差。以下是我可以从官方来源找到的内容:

Desktop browsers (including Firefox) use a default value of roughly 1.2, depending on the element's font-family. [MDN/line-height]

关于html - CSS 1em 改变浏览器默认行高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43033167/

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