CSS abbreviation skills

xiaoxiao2021-03-06  84

The key indicator of the availability of web websites is the speed, more specifically, is that the page can appear in the visitor's browser window with how fast speed. Factors affecting speeds There are many kinds, including the speed of the web server, the Internet connection of the visitor, and the file size that the browser must download. Although you can't control the speed of the server and connection, you can control the file size that makes up the website web page.

In order to make the website can be faster, the construction of the web will compress and optimize each image file on the website, which often makes the quality of the image in order to reduce the size of several percentage points. Quality. Since the CSS style sheet is a plain text file, the web builders rarely consider the size of its CSS style table file than the image. However, by using CSS abbreviations and some simple skills, you can reduce the size of the style sheet to a large extent. In my informal special test of my style sheet, I decreased the size of about 25-50%.

The abbreviation property of CSS using CSS is some dedicated nature name used to replace multiple related properties. For example, a Padding Property is an abbreviation of a top gap, a padding-right, a bottom gap, and a padding-left.

Using sketched properties allow you to compress multiple properties / attributes to a row code of the CSS style sheet. For example, I want to think about the following code:

. Sample1 {margin-top: 15px; margin-right: 20px; margin-ket: 24px; padding-top: 5px; padding-right: 10px; padding-iptom: 4px; padding-left: 8px Border-top-width: thin; border-top-style: solId; border-top-color: # 000000;

In order to replace it with some abbreviations, it is possible to reduce the code as the following, and the actual effect of the two is exactly the same:

.sample1 {margin: 15px 20px 12px 24px; Padding: 5px 10px 4px 8px; border-top: Thin Solid # 000000;

It should be noted that the abbreviation properties also have multiple properties, each (attribute) corresponds to a conventional nature that is combined into an abbreviation. The attribute is separated by a blank.

When the attribute is a similar value, for example, when the linear measurement of the border blank property, the order of the attribute after the abbreviation is very important. The order of the attribute begins with the top (top frame blank on top) and then continues with the lattice (Box).

If all the properties of the abbreviation, you can simply list a single property, then copy it four times in front. Therefore, the following two properties are equal:

Margin: 5px 5px 5px 5px;

Margin: 5px;

Similarly, you can use two attributes that are subjected to a blank or interval property to represent the top / bottom and right / left attribute pairs.

Margin: 5px 10px 5px 10px; Margin: 5px 10px;

The order of attributes is not important when they are not similar. Therefore, attributes such as the border color, the border style, and the border width can be connected in any order in the outline property. Ignore an attribute is equivalent to ignoring the conventional nature of the corresponding point in the style rules.

Here are the list of CSS abbreviations and the conventional properties they represent.

Background: Background Accessories, Background Colors, Background Images, Background Position, Background Repeat Border (Border): Border Color, Border Style, Border Width Border-Bottom: Border Color, Base Border Style, Base Border Width Border-Left (left border): left border color, left side frame style, left border width border-right (right side frame): right border color, right side frame style, right side border width Border-TOP (Top Border): Top Border Color, Top Border Style, Top Border Width CUE (Sound Tips): Before prompted, then prompt font (font): font, font size, font style, font thick, font variants, line height, font Size adjustment, font stretching List-style (list style): list style image, list style location, list style type margin (blank): top blank, right blank, bottom blank, left blank Outline (Outline): Outline Color , Outline style, outline width padding (gap): top gap, right gap, bottom gap, left gap PAUSE (pause): Post-suspend, pre-suspension reduction blank

Another way to reduce CSS style sheets is to delete most of the useless blank from the document. In other words, break each rule into a row code, that is, inserting the original to the code to split each property / attribute into different lines and indensors.

For example, the following code example is the same on the content, but the second is more refined:

H1 {font-size: x-large; font-weight: bold; color: # ff0000;}

H1 {font-size: x-large; font-weight: bold; color: # ff0000}

Delete

Removing the comment from your CSS code is another way to reduce the file size. Although the comment is useful for the reading of the code, it does not help the browser to generate your web page. Many web builders are used to add comments to each line of code, or at least give each rule statement. Such generous comments are rarely required in the CSS style sheet because most CSS properties and attributes are easy to read and understand. If you use meaningful names for classes, ids, and other selectors, you can save most of the annotations, while still keeping the code readability and maintainability.

H1 {/ * Heading 1 style * / font-size: x-large; / * x-large size * / font-weight: bold; / * bold * / color: # ff0000; / * red * /}

Using sketched properties, delete useless blank, omitting annotations can reduce the size of your CSS style sheet file to a large extent. This is in turn to make small goals accelerating your web site speed, but may be obvious contributions.

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

New Post(0)