Common CSS syntax

Source: Internet
Author: User
CSS syntax is indispensable for designing standard WEB pages. Generally, we can automatically generate the corresponding CSS code through the "CSS style" Panel of the Dreamweaver software. Although the CSS code generated by the software is clear and easy to understand, the CSS code reading is lengthy and complex due to the clear explanation of the style definition of the bar, at the same time, the number of CSS Code bytes is also increasing ...... This is intolerable for those pursuing high efficiency and perfection.
For example, when we define the padding size for an element and use padding, the code generated by the software may be as follows:

The following is a reference clip:
. T1 {
Padding-top: 3px;
Padding-right: 20px;
Padding-bottom: 3px;
Padding-left: 20px;
}

If it is easy to write

The following is a reference clip:
. T2 {
Padding: 3px 20px 3px 20px;
}

The four sides of padding correspond to top (top), right (right), bottom (bottom), and left (left ). Of course, this example can also be abbreviated:

The following is a reference clip:
. T3 {
Padding: 3px 20px 3px;
}

When left (left) is absent, the default value is right (right). If bottom (bottom) is absent, the default value is top (top, in this example, the simplest is:

The following is a reference clip:
. T4 {
Padding: 3px 20px;
}

(Of course, if padding is a value, it indicates that the top right bottom left is the same .)

The following is a reference clip:
<Style type = "text/css">
<! --
. T1 {
Padding-top: 3px;
Padding-right: 20px;
Padding-bottom: 3px;
Padding-left: 20px;
}
. T2 {
Padding: 3px 20px 3px 20px;
}
. T3 {
Padding: 3px 20px 3px;
}
. T4 {
Padding: 3px 20px;
}
Span {
Border: 1px solid # CCCCCC;
}
-->
</Style>
<Span class = "t1"> cnbruce </span>
<Span class = "t2"> cnrose </span>
<Span class = "t3"> cnjames </span>
<Span class = "t4"> www.cnbruce.com </span>

In the above example, four lines of code in the lengthy section t1 are condensed into one line of introduction code, which is the advantage of CSS abbreviations.

Of course, many times we will see many similar CSS abbreviations when learning other people's CSS experience. However, if you do not understand the CSS method, you cannot understand it. Therefore, we must understand and master some common CSS abbreviations and syntaxes. Using abbreviations can help reduce the size of your CSS file and make it easier to read. The main rules for css abbreviations are as follows:

Color

The hexadecimal color value. If the two values are the same, they can be abbreviated in half. For example, #000000 can be abbreviated as #000; #336699 can be abbreviated as #369;

Box Size

There are usually four writing methods:

Property: value1; indicates that all edges are value1;
Property: value1 value2; the value of top and bottom is value1, and the value of right and left is value2.
Property: value1 value2 value3; indicates that the top value is value1, the right and left values are value2, and the bottom value is value3.
Property: value1 value2 value3 value4; four values in turn represent top, right, bottom, left

Easy to remember is clockwise, top right bottom left. An example of the specific application in margin and padding is as follows:

Margin: 1em 0 2em 0.5em;

Border (border)

The border attributes are as follows:

The following is a reference clip:
Border-width: 1px;
Border-style: solid;
Border-color: #000;
It can be abbreviated as border: 1px solid #000;

Syntax: border: width style color;

Background (Backgrounds)

The attributes of the background are as follows:

The following is a reference clip:
Background-color: # f00;
Background-image: url(background.gif );
Background-repeat: no-repeat;
Background-attachment: fixed;
Background-position: 0 0;
It can be abbreviated as: background: # f00 url(background.gif) no-repeat fixed 0 0;

The syntax is background: color image repeat attachment position;

You can omit one or more attribute values. If this attribute value is omitted, the default value of the browser is used. The default value is:

The following is a reference clip:
Color: transparent
Image: none
Repeat: repeat
Attachment: scroll
Position: 0% 0%

Fonts)

The font attributes are as follows:

The following is a reference clip:
Font-style: italic;
Font-variant: small-caps;
Font-weight: bold;
Font-size: 1em;
Line-height: 140%;
Font-family: "Lucida Grande", sans-serif;
It can be abbreviated as: font: italic small-caps bold 1em/140% "Lucida Grande", sans-serif;

Note: If you are short for font definition, you must at least define the font-size and font-family values.

List (lists)

To cancel the default dot and serial number, you can write list-style: none ;,

The list attributes are as follows:

The following is a reference clip:
List-style-type: square;
List-style-position: inside;
List-style-image: url(image.gif );
Can be abbreviated as: list-style: square inside url(image.gif );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.