CSS's eighteen skills

xiaoxiao2021-03-05  21

* Original Author: Roger Johansson * About the author: live in Gothenburg, Sweden, in 1994, came into contact with and involved in web design, 456 Berea Street was his home address, so the use of this name as his personal home page domain name * ORIGINAL: www.456bereastreet. COM * Originally Published: March 15, 2005 * Abie Description: This article "CSS TIPS AND TRICKS", 2 articles, I combined them into translation in this article. Recently, there are often friends asking me some CSS issues encountered. They can't control CSS very well, affecting the efficiency of CSS. Let me analyze the error, help everyone easier to use CSS. This article summed up all the skills and compatibility programs I have started using the CSS layout method. I am willing to share these with you, I will focus on the mistakes of some novices (including myself also committed), if you are already CSS Master, these experience skills may already know, if you have more, I hope I can help me. 1. Use the CSS abbreviation usage to help reduce the size of your CSS file, easier to read. The main rules of CSS abbreviations are given to "Common CSS Abblast Summary Summary", which is not expanded here. II. Clearly defined units unless the value of 0 forgotting the defined size is a universal error in CSS. In HTML, you can write only width = "100", but in CSS, you must give an accurate unit, such as: Width: 100px Width: 100em. Only two exceptions may not be defined: rows and 0 values. In addition, other values ​​must keep up with the unit, not to add binding between the values ​​and units. 3. Size mode is used in XHTML using CSS, and the element name defined in CSS is case sensitive. In order to avoid this error, I recommend that all definition names use lowercase. The values ​​of Class and ID are also case sensitive in HTML and XHTML. If you must write a mixed write, please make a closer to confirm that you are in the definition of CSS and the labels in XHTML are consistent. IV. Cancel the element before the Class and ID define when you write to an element definition Class or ID, you can omit the previous elements define because the ID is unique in one page, while CLAS S can be used multiple times in the page. You define a certain element. For example: div # content {/ * declarations * /} fieldSet.details {/ * Declarations * /} can be written into a #content {/ * declarations * /} .details {/ * declarations * /} can save some bytes. 5. The default value is usually the default value of Padding is 0, and the default value for Background-Color is Transparent. But the default value of different browsers may be different. If you are afraid of conflict, you can define all the elements of the margin and padding values ​​in the style table, like this: * {margin: 0; padding: 0;} 6. No need to repeat the definition of the inherited value CSS In the middle, the child element automatically inherits the attribute value of the parent element, the color, font, etc. But note that the browser may override your definition with some default values.

7. Recent priority principles If there are a variety of definitions of the same element, the definition of the close (minimum level) is best, for example, there is such a code UPDATE: Lorem Ipsum Dolor Set in the CSS file, you have defined Element P, also defined a class "update" p {margin: 1em 0; font-size: 1em; color: # 333;}. Update {font-weight: bold; color: # 600;} These two definitions Class = "Update" will be used because the Class is closer than p. You can check out the W3C's "Calculating A Selector's Specificity" to learn more. Eight. Multiple CLASS Defines a tab to simultaneously define multiple Class. For example: Let's define two styles, the first style background is # 666; the second style has a border of 10 px. .one {width: 200px;}. two {border: 10px solid # f00;} In the page code, we can call this final display effect is this DIV existing # 666 background, there is 10px Border. Yes, this is ok, you can try it. Nine. User selectors CSS beginners do not know that the use of sub-selectors is one of the reasons that affect their efficiency. Subsets can help you save a lot of Class definitions.

Let's look at the following code:

转载请注明原文地址:https://www.9cbs.com/read-32166.html

New Post(0)