CSS规则的结构和Grouping、class和id

2016-02-19 23:39 2 1 收藏

有了下面这个CSS规则的结构和Grouping、class和id教程,不懂CSS规则的结构和Grouping、class和id的也能装懂了,赶紧get起来装逼一下吧!

【 tulaoshi.com - Web开发 】

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/webkaifa/)rules::=selector        左括号declarations右括号declarations::= declaration{SEMICOLONdeclaration}[SEMICOLON]SEMICOLON::=分号declaration::=propertyCOLONvalueCOLON::=冒号value::=keyword listkeyword list::=keyword{SPACEkeyword}SPACE::=空格 通常会用空格做为value之间的分隔符,有个例外:As we've seen, CSS keywords are separated by spacesexcept in one instance. In the CSS property , there is exactly one place where a forward-slash () can be used to separate two specific keywords. Here's an example:h2 {font: large/150% sans-serif;}The slash separates the keywords that set the element's font size and line height. This is the only place the slash is allowed to appear in the declaration. All of the other keywords allowed for are separated by spaces.  selector: defines which piece of the document will be affected.Selector通常是html元素,也可能是xml中允许任何元素。将多个元素共用一个style,例子:
/* group 1 */
h1 {color: silver; background: white;} h2 {color: silver; background: gray;} h3 {color: white; background: gray;} h4 {color: silver; background: white;} b {color: gray; background: white;}  /* group 2 */ h1, h2, h4 {color: silver;} h2, h3 {background: gray;} h1, h4, b {background: white;} h3 {color: white;} b {color: gray;}  /* group 3 */ h1, h4 {color: silver; background: white;} h2 {color: silver;} h3 {color: white;} h2, h3 {background: gray;} b {color: gray; background: white;}2.2.1.1 The universal selector* {color: red;}例子:h1 {font: 18px Helvetica;} h1 {color: purple;} h1 {background: aqua;}h1 {  font: 18px Helvetica;  color: purple;  background: aqua; }If the second semicolon is omitted, however, the user agent will interpret the style sheet as follows:h1 {  font: 18px Helvetica;   color: purple background: aqua; }Since : is not a valid value for , and also since can be given only one keyword, a user agent will ignore the declaration (including the : part) entirely. It might render s as purple text without an aqua background, but more likely, you won't even get purple s. Instead, they'll be the default color (usually black) with no background at all. (The declaration : will still take effect since it was correctly terminated with a semicolon.)就是同时group selector和declarationh1, h2, h3, h4, h5, h6 {color: gray; background: white; padding: 0.5em;  border: 1px solid black;} You've grouped the selectors, so the styles on the right side of the rule will be applied to all the headings listed, and grouping the declarations means that all of the listed styles will be applied to the selectors on the left side of the rule. 最简单的selector是只针对文档元素的element selecoter,还有两种selecotrs:class selectors和id selectors。这两种selector可以独立于文档元素的,即不是于具体某个的文档元素直接关联的。这两种selecoter可以单独使用,也可以和element selector一起使用。但是这两种selector的使用需要配合文档编写的规范性。比如写一个讨论plutonium处理方式的文档,文档由很多段组成,包含很多警告信息,希望将警告的字体置为bold,以突出显示。但是这些警告信息的格式很多,一段文字,列表式,一小节文本等。所以不能通过p {font-weight: bold;}的形式来定义。这样无法从全是文本的整个文档中找到警告信息,并加粗。因此,解决方式:使用class selectors给警告信息的部分加上标记。

来源:https://www.tulaoshi.com/n/20160219/1630312.html

延伸阅读
标签: Web开发
在前几日的文章中我提到过XHTML的重要性,在那篇文章中我讲了为什么说XHTML结构重要,重视XHTML结构的好处。但是那篇文章从开发的效率入手,并没有深入细节,而今天的这篇文章是讲XHTML中的细节部分的,可以说是上一篇的续述。这篇续述的主题就是ID与CLASS怎么用,在标题中有提及使用原则与技巧,这里的使用原则与技巧是我的经验总结,并非摘自...
标签: Web开发
XHTML CSS网页布局中ID与class的理解应用: 要是XHTML与CSS能面向对象。。太阳应该从北边升起了。但是,凡事都应该带着OO的思想来看问题,也勉强可以凑数拉。其实,早在零几年就有人提出了OO-style,不过已找不到。 那要怎样OO呢?现在大家都知道CSS是可以介样写滴: .G_G { /* xxxxxx */ } 我们可以把它大约看一个...
标签: Web开发
CSS的命名在webjx.com中,曾经多次讨论过。说实话,看到这个题目时我觉得这有什么好讨论的,肯定会是场一边倒的讨论。因为个人比较倾向于短命名,简单优雅,可能是出于程序员的洁癖,容不得任何冗余的东西。和我一个想法的人应该不在少数吧! 先看下长命名和短命名的定义: !-- 长命名:使用前缀体现上下文环境的CSS命名方式。 -- d...
标签: flash教程
1. 最基本的Class定义方面我不多说了, 就举个例子直接开始: class Flash8 { private var user:String; //定义变量 private var pass:String; private var age:Number; public function Flash8(x:String, y:String) { //class的结构函数 user = x; pass = y; trace("用户名 = "+user+", 密码 = "+pass); } public function setAge(x:Num...
标签: Web开发
前面的学习我们仅仅使用HTML选择器(在HTML页面里为html标签,如 P) 现在我们学习使用clss和id定义属于自己的选择器。 这样,同样的html元素可以通过class或ID使用不同的表现。 在CSS里,使用点号(.)创建class选择器,使用hash符号(#)创建ID选择器。 例子: #top {     background-color:&...

经验教程

551

收藏

63
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部