我有一个CSS文件。使用line-height: 1em;属性,文本如下所示:

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

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

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

1em应该等于已经存在的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的原因,因为在大多数情况下,两行之间没有空格只会导致可读性差。这是我可以从官方来源找到的内容:


  桌面浏览器(包括Firefox)使用的默认值大约为1.2,具体取决于元素的字体系列。 [MDN/line-height]

09-30 17:31