CSS Learning Note 1

Source: Internet
Author: User

CSS Basic syntax
selector {declaration1; declaration2; ... declarationn}
Declaration Property:value, Declaration use semi-colon segmentation, the last statement after the proposed addition '; ' As the end
If the attribute contains spaces, you need to add double quotation marks to the property value ""
CSS itself is case-insensitive, but when applied to HTML, class and ID names are case-sensitive

1. Group Selector
H1,h2,h3,h4,h5,h6 {
Color:green;
}

2. Deriving selectors
Li Strong {
Font-style:italic;
Font-weight:normal;
}

Only valid for elements within <li><strong></strong></li> tags

3.id Selector
#red {color:red;}
#green {color:green;}
<p id= "Red" > This paragraph is red. </p>
<p id= "Green" > This paragraph is greenish. </p>

ID selector and Derivation selector
#sidebar p {
Font-style:italic;
Text-align:right;
Margin-top:0.5em;
}

Only the P element with ID sidebar is in effect

4. Class selector
. Center {Text-align:center}
Class selector is displayed with a dot number

. Center {Text-align:center}
&LT;H1 class= "center" >
This heading'll be center-aligned

<p class= "center" >
This paragraph'll also be center-aligned.
</p>
Class-matching elements will take effect

As with the ID, class can also be used as a derived selector:
. Fancy TD {
Color: #f60;
Background: #666;
}

Take effect on TD elements of elements in class= "Fancy"

Elements can also be selected based on their classes:
td.fancy {
Color: #f60;
Background: #666;
}
Yes and only for TD elements that are class fancy
&LT;TD class= "Fancy" ></td>

5. Property selector
Sets the style for the HTML element with the specified property.
You can set the style for the HTML element that owns the specified property, not just the class and ID properties.
Note: Only in the rules! DOCTYPE, IE7 and IE8 only support property selectors. In IE6 and lower versions, attribute selection is not supported.

The following example sets the style for all elements with the title property:

Property Selector >>
[Title]
{
color:red;
}
&LT;H2 title= "Hello World" >hello world
<a title= "W3school" href= "http://w3school.com.cn" >W3School</a>

Properties and Value selectors >>
[Title=w3school]
{
BORDER:5PX solid blue;
}

<a title= "W3school" href= "http://w3school.com.cn" >W3School</a>

Properties and value selectors-multiple values >>
The following example sets the style for all elements that contain the title property of the specified value. Applies to property values separated by spaces:
[Title~=hello] {color:red;}
&LT;H2 title= "Hello World" >hello world
<p title= "Student Hello" >hello w3school students!</p>

The following example sets the style for all elements with the lang attribute that contains the specified value. Applies to attribute values separated by hyphens:
[Lang|=en] {color:red;}
<p lang= "en" >Hello!</p>
<p lang= "en-US" >Hi!</p>

Set the style of a form
The property selector is especially useful when styling a form that does not have a class or ID:
Input[type= "Text"]
{
width:150px;
Display:block;
margin-bottom:10px;

Font-family:verdana, Arial;
}

Input[type= "button"]
{
width:120px;
margin-left:35px;
Display:block;
Font-family:verdana, Arial;
}

<form name= "Input" action= "" method= "get" >
<input type= "text" name= "name" value= "Bill" size= ">"
<input type= "text" name= "name" value= "Gates" size= ">"
<input type= "button" value= "Example button" >
</form>

apply CSS within HTML, and multiple style definitions
Http://www.w3school.com.cn/css/css_howto.asp

CSS Learning Note 1

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.