简体   繁体   English

关于标题的CSS3样式

[英]About CSS3 style for heading 1

Okay, I have one <h1> in my <header> , and one <h1> in my <section>. 好的,我在<header>中有一个<h1>,在<section>中有一个<h1>。 The first question is why the size of this both <h1> different? 第一个问题是为什么这两个<h1>的大小不同? I assume that they have their own size depends on their parents tags, which is I'm not certain of it. 我认为他们自己的大小取决于他们的父母标签,我不确定。 The second is I have styling this <h1> with external CSS, like: 第二个是我用外部CSS设置<h1>的样式,例如:

h1{
   font-size:2em; 
}

tutorial but, the <h1> inside the <header> won't change, only the <h1> inside the <section> make sense. 教程,但是<header>内的<h1>不会改变,只有<section>内的<h1>才有意义。 I'm still beginner even in html, so please explain nicely. 即使在html中,我仍然是初学者,所以请解释清楚。 Thanks in advance. 提前致谢。

Issue demo: http://jsfiddle.net/c06tpb3u 问题演示: http : //jsfiddle.net/c06tpb3u

You're not using any CSS reset, which means you're at the browser's mercy and the default Stylsheet . 您没有使用任何CSS重置,这意味着您将受到浏览器的怜悯和默认的Stylsheet的影响

h1 {
    display: block;
    font-size: 2em;
    font-weight: bold;
    margin: 0.67em 0;
}

are the default styles set for h1 heading element 是为h1标题元素设置的默认样式

while for section things are getting salty: 而对于section事情变得越来越咸:

h2, *:-moz-any(article, aside, nav, section) h1 { /*<<<< note h1 here*/
    display: block;
    font-size: 1.5em; /*<<<< and the new value*/
    font-weight: bold;
    margin: 0.83em 0;
}
h1 {
    /*display: block;*/
    /*font-size: 2em;*/
    /*font-weight: bold;*/
    /*margin: 0.67em 0;*/
}

so as you can notice (the above is inspecting in FF) that h1 is getting overwritten for h1 being inside section . 因此,您可以注意到(上面是在FF中进行的检查),因为h1位于section ,所以h1被覆盖。 <heading> element is omitted from that group leaving heading1 at the 2em default font size. 该组中省略了<heading>元素,将heading1保留为默认的2em字体大小。

Browsers' default CSS for HTML elements 浏览器的HTML元素默认CSS
https://developer.mozilla.org/en/docs/Web/CSS/length https://developer.mozilla.org/en/docs/Web/CSS/length

em EM
This unit represents the calculated font-size of the element. 该单位表示计算出的元素的字体大小。 If used on the font-size > property itself, it represents the inherited font-size of the element. 如果在font-size>属性本身上使用,它表示元素的继承的font-size。 This unit is often used to create scalable layouts, which keep the vertical rhythm of the page, even when the user changes the size of the fonts. 该单元通常用于创建可缩放的布局,即使用户更改字体大小,该布局也可以保持页面的垂直节奏。 The CSS properties line-height, font-size, margin-bottom and margin-top often has a value expressed in em. CSS属性line-height,font-size,margin-bottom和margin-top通常具有以em表示的值。

To override any CSS add the !important notation to the style.. 要覆盖任何CSS,请在样式中添加!important表示法。

h1{
   font-size:2em !important; 
}

This will override any of the browsers default CSS. 这将覆盖任何浏览器的默认CSS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM