简体   繁体   English

标题标签的默认CSS样式是什么? (H1,h2,h3,h4,h5)

[英]What are the default CSS styling of heading tags? (H1, h2, h3, h4, h5)

In HTML, headings are denoted with <H> (1,2,3,4,5,6) tag. 在HTML中,标题用<H> (1,2,3,4,5,6)标记表示。

My question is regarding following HTML code: 我的问题是关于以下HTML代码:

<div class="pure-u-1-1 pure-u-lg-3-3">
    <h3><form:label path="gen">Registrer Bruker</form:label></h3>
</div>

Instead of writing <H3> , i want to write property of class in CSS ; 而不是写<H3> ,我想在CSS中写类的属性; which gives same font size (look and feel); 它提供相同的字体大小(外观和感觉); as of heading HTML gives. 标题HTML给出。 Also is there predefined property for same in CSS? CSS中是否也有相同的预定义属性?

The answer is no, however you might hack the styles. 答案是否定的,但是你可能会破解这些风格。 Most browsers will try to use these styles 大多数浏览器都会尝试使用这些样式

(Taken from: w3schools ) (摘自: w3schools

h1 { 
    display: block;
    font-size: 2em;
    margin-top: 0.67em;
    margin-bottom: 0.67em;
    margin-left: 0;
    margin-right: 0;
    font-weight: bold;
}
h2 {
    display: block;
    font-size: 1.5em;
    margin-top: 0.83em;
    margin-bottom: 0.83em;
    margin-left: 0;
    margin-right: 0;
    font-weight: bold;
}
h3 { 
    display: block;
    font-size: 1.17em;
    margin-top: 1em;
    margin-bottom: 1em;
    margin-left: 0;
    margin-right: 0;
    font-weight: bold;
}
h4 { 
    display: block;
    margin-top: 1.33em;
    margin-bottom: 1.33em;
    margin-left: 0;
    margin-right: 0;
    font-weight: bold;
}
h5 { 
    display: block;
    font-size: .83em;
    margin-top: 1.67em;
    margin-bottom: 1.67em;
    margin-left: 0;
    margin-right: 0;
    font-weight: bold;
}
h6 { 
    display: block;
    font-size: .67em;
    margin-top: 2.33em;
    margin-bottom: 2.33em;
    margin-left: 0;
    margin-right: 0;
    font-weight: bold;
}

Are there predefined property for same in CSS; CSS中是否有相同的预定义属性; which gives same look and feel as H gives? 它给出了与H相同的外观和感觉?

No. 没有。

The default style of a heading is (in most browsers) exactly that: a collection of different CSS rules coupled with an Hn selector (and stored in the browser stylesheet). 标题的默认样式(在大多数浏览器中)恰好是:与Hn选择器结合的不同CSS规则的集合 (并存储在浏览器样式表中)。

There isn't a (plain CSS) way to automatically copy all of those rules. 没有(简单的CSS)方法来自动复制所有这些规则。

You could use the Inspector tool that comes in the developer tools built into most browsers to examine a heading and look at the default rules for it, and then copy those rules to your own (author) stylesheet. 您可以使用大多数浏览器中内置的开发人员工具中的Inspector工具来检查标题并查看其默认规则,然后将这些规则复制到您自己的(作者)样式表中。

There may be some variations between browsers, so you'll generally want to set the Hn rules explicitly too. 浏览器之间可能存在一些差异,因此您通常也希望明确设置Hn规则。

Question: is there predefined property for same in CSS? 问题:CSS中有相同的预定义属性吗?

No 没有

You can try like this: 你可以尝试这样:

h3{ 
   display: block; 
}

h3 {
   font-size: /*Font size similar to h3*/ ;
}

Think a good practice is let h<1-6> keep their default styles. 认为一个好的做法是让h <1-6>保持其默认样式。 And then add a class to add additional styles. 然后添加一个类来添加其他样式。 Just seems cleaner to me, and you are not hacking the "master styles." 对我来说似乎更干净,而且你并没有破解“主人风格”。 Pros and Cons I'm sure. 优点和缺点我敢肯定。

<h1 class="h1">Hello CSS</h1> <h1 class =“h1”> Hello CSS </ h1>

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

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