Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 在div和h1上设置字体大小的差异_Html_Css - Fatal编程技术网

Html 在div和h1上设置字体大小的差异

Html 在div和h1上设置字体大小的差异,html,css,Html,Css,直接在div容器上设置某些属性与直接在容器中的元素上设置属性有什么区别。例如字体大小: <div class="the_last_of_us"> <h5>Cookie Settings</h5> </div> Cookie设置 在div上设置font size与上例中的h1或h5之间的主要区别是,默认情况下,h5不会继承font size,因为它会从用户代理样式表中选择样式,除非您明确定义它为继承,例如 h5 { font-size:

直接在
div
容器上设置某些属性与直接在容器中的元素上设置属性有什么区别。例如
字体大小

<div class="the_last_of_us">
  <h5>Cookie Settings</h5>
</div>

Cookie设置

div
上设置
font size
与上例中的
h1
h5
之间的主要区别是,默认情况下,
h5
不会继承
font size
,因为它会从用户代理样式表中选择样式,除非您明确定义它为继承,例如

h5 {
  font-size: inherit;
}
而在
h5
上显式设置
font size
将覆盖用户代理样式表,并设置您为
h5
元素定义的
font size


在其他场景中,在父元素上设置属性是有意义的,它将由几个元素继承。这将帮助您保持较低的选择器特异性。例如,将
color
设置为
div
可以由
h1
元素继承

因此,不是一个具有如下属性的选择器

div h5 {
  color: #f00;
}
你可以用

div {
  color: #f00; /* Also applies color to any element inside 
                  the div which can inherit color from the parent element */
}