7th days: getting started with CSS

Source: Internet
Author: User
ArticleDirectory
    • 1. Basic syntax Specification
    • 2. color value
    • 3. Define the font
    • 4. Group Selector
    • 5. Derivative Selector
    • 6. ID Selector
    • 6. Category Selector
    • 7. Define the link Style

Learn about XHTMLCodeAfter standardization, We need to conduct CSS layout. First, we will introduce some introduction to CSS. If you are familiar with it, you can skip this section and go directly to the next section.

CSS is short for Cascading Style Sheet. It is a simple mechanism for adding styles to Web documents and belongs to the layout language of the presentation layer.

1. Basic syntax Specification

Analyze a typical CSS statement:

P {color: # ff0000; Background: # ffffff}

    • "P" is called "selector", indicating that we want to define a style for "p;
    • Style declaration is written in a pair of braces;
    • Color and background are called "properties". Different properties are separated by semicolons;
    • "# Ff0000" and "# ffffff" are attribute values ).
2. color value

Color values can be written in RGB values, for example:Color: RGB (255, 0, 0)And can also be written in hexadecimal format, as in the above example.Color: # ff0000. If the hexadecimal value is repeated in pairs, the effect is the same. For example, # ff0000 can be written as # f00. However, it cannot be abbreviated if it is not repeated. For example, # fc1a1b must be filled with six characters.

3. Define the font

The following font definition method is recommended for web standards:

Body {font-family: "lucida Grande", verdana, lucida, Arial, Helvetica,, sans-serif ;}

    • The font is selected in the listed order. If your computer contains the lucida Grande font, the document will be specified as lucida grande. If no, It is specified as the verdana font. If no verdana is available, it is specified as the lucida font, and so on ,;
    • Lucida Grande fonts are suitable for Mac OS X;
    • Verdana fonts are suitable for all Windows systems;
    • Lucida is suitable for Unix users
    • "" Is suitable for simplified Chinese users;
    • If none of the listed fonts are available, the default sans-serif font can be called;
4. Group Selector

When the style attributes of several elements are the same, you can call a declaration. elements are separated by commas ,:P, TD, Li {font-size: 12px ;}

5. Derivative Selector

You can use the derived selector to define a style for the child element in an element. For example:

Li strong {font-style: italic; font-weight: normal ;}

The child element strong under Li defines a italic style that is not bold.

6. ID Selector

The CSS layout is mainly implemented by the "Div" layer, and the DIV style is defined by the "id selector. For example, we first define a Layer

<Div id = "menubar"> </div>

Then define in the style sheet as follows:

# Menubar {margin: 0px; Background: # fefefefe; color: #666 ;}

Here, "menubar" is your own defined ID name. Add "#" to the front.

The ID selector also supports derivation, for example:

# Menubar P {text-align: Right; margin-top: 10px ;}

This method is mainly used to define layers and those that are complicated and have multiple derived elements.

6. Category Selector

In CSS, a class selector definition starts with a vertex, for example:

. 14px {color: # f60; font-size: 14px ;}

On the page, use the class = "Class Name" method to call:

<SPAN class = "14px"> 14 PX font </span>

This method is simple and flexible, and can be created and deleted at any time according to the page requirements.

7. Define the link Style

In CSS, four pseudo classes are used to define the link styles: A: Link, A: visited, A: hover, And A: active. For example:

A: link {font-weight: bold; text-Decoration: none; color: # c00 ;}
A: visited {font-weight: bold; text-Decoration: none; color: # C30 ;}
A: hover {font-weight: bold; text-Decoration: underline; color: # f60 ;}
A: active {font-weight: bold; text-Decoration: none; color: # f90 ;}

The preceding statements define the style of "link, accessed link, mouse over, and mouse over. Note: The data must be written in the above sequence; otherwise, the display may be different from what you expected. Remember that their order is "lvha ".

Haha, after reading so much, I feel a little dizzy. In fact, there are still many CSS syntax specifications. Here we only list some common ones. After all, we are step-by-step, and it is impossible to become a fat man at a Glance :)

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.