In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what is the function and meaning of css code optimization". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the function and significance of css code optimization".
The sense and significance of css Code beautification
1. Reduce the consumption of web page bytes. Under the same premise, tighten the time for browsers to download css code, to slow down the opening rate of web pages.
2. Easy to maintain. Simplifying and standardizing css code reduces css code and facilitates future maintenance
3. Make the css code I write more professional.
Css beautification-need to beautify the center of the css code
1. Abbreviate css code.
2. Separate css codes.
3. Share the css determiner for the same attribute extraction.
4, sloppy web page tone and background configuration format (important preference for larger sites).
5. Hierarchical css code.
An example is given to illustrate the div css beautification methods mentioned above.
1. Abbreviate css code
The important abbreviations css attribute codes are often used as follows:
Bac kg round (backup attributes-CSS manual detailed awareness bac kg round manual)
Before beautification
Bac kg round-color:#FFF; corresponding attribute for mountain color mining is pure white
Background-image:url (CSS5.gif); the corresponding attribute is to set the equipment to configure the CSS5.gif image as a matching scene.
Bac kilogram round-position:bottom; backup picture is at the bottom.
Bac kg round-repeat:repeat-x; background is locked again and again according to X coordinate (Abscissa)
The above CSS code can be abbreviated to
Bac kg round:#FFF url (CSS5.gif) repeat-x bottom
Express: the backing color is pure white, and repeat the CSS5.gif picture in X coordinates, not to mention the icon. Unoptimized css bac kilogram round attributes are common
Margin (external complement attribute-CSS manual is familiar with margin manual)
Before optimization
Margin-left:5px; means 5px on the left.
Margin-right:6px; to the right 6px
Margin-bottom:7px; bottom stretch 7px
Margin-top:8px; top wrinkle 8px
Optimization abbreviated to
Margin:8px 6px 7px 5px; meaning and attribute achievements are the same as above. You can understand the introduction of css margin in detail.
Padding (internal padding attribute-CSS manual details padding manual)
Before optimization
Padding-left:5px; means left blanking 5px.
Padding-right:6px; right blanking 6px
Padding-bottom:7px; bottom (bottom) whitening 7px
Padding-top:8px; top (top) white 8px
Beautify the abbreviation as
Padding:8px 6px 7px 5px; meaning and attribute achievements are the same as above. You can learn more about the introduction to css padding.
Border (Border Properties-CSS manual specific border manual)
Before optimization
The border color of border-color:#000000; is color
The border-style:solid; frame pattern is solid.
Border-width:1px; border width is 1px
Maybe it's abbreviated to
Border:1px solid # 0000000; same as above before optimization
It is assumed that only the right border is set to 1px and the color is black under the solid line css code
Border-left:1px solid # 000000
Font (font attributes-CSS manual is specific to fonts manual)
The properties of the font are as follows:
Font-style:italic; font format
Font-variant:small-caps; font variant
Font-weight:bold; font bold
Font-size:12px; word size is 12px
The line height of line-height:22px; is 22px
Font-family: "boldface" font is boldface
Dayao is abbreviated to one sentence: font:italic small-caps bold 12px/22px "boldface"
Note that if you abbreviate the font definition, at most you need to define two values, font-size and font-family, that are familiar with css font capabilities.
Understand what px is.
2. Separate css codes.
As usual, our code is listed below.
This will take up a lot of space and carriage return space in css files, and it also takes up 12 lines of css file space.
Css5.com.cn suggests that you rewrite it to
/ * CSS css5.com.cn example illustration * /-here is the css comment
.yangshi {font-size:12px;border:1px solid # 000000 / paddinglv 5px;}
.yangshi2 {font-size:12px;border:1px solid # 0000X paddingpurl 5px;}
How will waste spaces and return spaces, and the number of css file lines, thus throttling code file bytes.
3. Share the css determiner for the same attribute extraction.
This should be clear is that if there are two small pieces of css attributes such as width and height font color are similar, and there is a little disagreement, at this moment we are important to extract everyone's common css, name a css attribute decider, thus saving css code.
Such as:
/ * CSS css5.com.cn div+css example illustration * / .yangshi {font-size:12px;border:1px solid # 000000transpaddingVOL5px; width:25px;} .yangshi2 {font-size:12px;border:1px solid # 000000entpaddingPADRING 5px5px; width:50px;}
The two techniques of yangshi and yanshi2 here have the same font size as 12px, the border is opposite, the inner blanks repel each other, and there is only a width difference. At this time, we will be able to extract their mutually exclusive parts and build a new css selector and reuse.
The new css property resolver is demonstrated as follows
.gongyong {font-size:12px;border:1px solid # 0000X paddingVOL5px;} .yangshi {width:25px;} .yangshi2 {width:50px;}
How when calling css-know the introduction of css
Div css
Div css tricks 2
How about to misappropriate the same name as css, and then separately call the non-css attribute class, the above examples can not show its benefits, but if there is a lot of code and there are many of the above personalities, it will show its yield nature.
4. Separate the color of the web page and the configuration style of the scenery (the larger site needs to pay attention to).
This point has the above third point with attribute extraction shared css decision maker in common, but the difference is central, if the station is relatively large, you need to change a center to tamper with the entire site page font color pattern, backing pattern color, frame tone name.
At this time we will be critical in the development of div+css when the root font fancy, backer pattern color, frame and other colors extracted together or put into a css file, such as easy for us to protect and renovate the basic style of the entire site.
5. Hierarchical css code.
The implication of hierarchical css code is to tidy up and classify the css code, such as the style of the css code selector at the control header, part, and bottom, and separate it from other central css code.
For example, the css code in the header is separated from the css code in the pattern area by entering each line.
As the above "toubu" and "dibu" can be distinguished by row separation, the good thing is that the rear guard facilitates convenience, so it is easy to identify and change the guard.
Thank you for your reading, the above is the content of "what is the function and meaning of css code optimization". After the study of this article, I believe you have a deeper understanding of what the role and significance of css code optimization is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.