4th Chapter CSS3

Source: Internet
Author: User

CSS3 notes

A: What is CSS3?
It is used for Web page style design, is the Web page looks more beautiful, very clear
CSS3 is an upgraded version of CSS

Two: The advantages of CSS?
1. Separation of content and performance
2. Web pages are more unified in their presentation and are more flexible to modify
3. Rich style, make the page layout more flexible
4. Reduce the amount of code, increase browsing speed, save broadband traffic
5. The use of independent CSS, is conducive to Web page search engine included

Three: What is the basic grammar of CSS3?
Comments in HTML:<!--This is a comment in HTML--
Comments in CSS3:/* This is a comment in the CSS3 */

Grammar:
selector {
Statement 1;
Statement 2;
......
}
eg
h1{
font-size:12px; (1)
Color:red (#000000);(2)
}
(1) (2) Call statement
Note: The last statement of CSS can not be written ";", but based on the standard specification, it is recommended to write

Style labels <style></style>
Grammar:
<style type= "Text/css" >-------> Style/text or CSS style
h1{
font-size:12px; (1)
Color:red (#000000);(2)
}
</style>

Four: What are the basic selectors for CSS3? What are the rules of grammar?
1:id selector: #header {}
2: Class selector:. header{}
3: Element selector: h1{}
4: Subclass selector: ul > li{}
5: Descendant selector: Div p{}
6: Pseudo-class selector: a:hover{}
7: Property Selector: input[type= "text"]{}


1) ID selector priority higher than class selector
2) The following style overrides the previous style ID before the class
3) higher than the inheritance specified

ID Selector
<title>CSS3</title>
<style type= "Text/css" >
#p {
Text-align:center;
Color: #3F0}

p{
Color
#C0F;}
</style>

<body>
<p id= "P" >hello world!</p>
<p> This label does not hand affect </p>
</body>
Note: The id attribute does not start with a number, the number begins in the browser (FIREFOX) does not work


Class Selector

<title> class Selector </title>
<style type= "Text/css" >
. Center{text-align:center;
Color: #F00;
}
. center1{
font-size:36px;
Color: #0F0;
}
body{
Background-color: #CF0;
}
</style>


<body>

<H1 class= "center" > Title Center
<p class= "Center1" > Paragraph center </p>
</body>
Note: The first character of the class name does not start with a number, and the number begins in the browser (FIREFOX) does not work


Priority of the base selector
1.ID selector > class selector > tag Selector
2. Does the tag selector also follow the "nearest principle": Do not follow
3. Regardless of the CSS style referenced in that way, generally follow the id > class > tag

Five: What are the advanced selectors for CSS3?

Hierarchy Selector
Type selector description syntax
The descendant selector E F selects the matching f element, and the matching f element is wrapped in body p{background:red;}
Contained within a matching e element
The sub-selector e>f selects the matching f element, and the matching f element is a body>p{background:red;}
A child element of the E element
The adjacent sibling selector E+f selects the matching f element, and the matching F-element is body+p{background:red;}
After the matched e element
The General Brotherhood selector E~f selects the matching F element and is located in the matching E element body~p{background:red;}
After all the matching F-elements

Demo:
<title> hierarchy selector </title>
<style type= "Text/css";
p,ul{
border:1px Solid red;/* Border Properties */
}

/* Descendant selector */
/*body p{
background:red;
} */
/* Sub-selector */
/*body>p{
background:red;
} */
/* Adjacent sibling selector */
/*.ac + p{
background:red;
}
#bc + p{
Background: #0F0;
} */
/* Universal Sibling Selector */
/*.ac~p{
Background: #0F0;
} */

</style>

<body>
<p class= "AC" >1</p><!--presentation of adjacent sibling selectors, Add a class-->
<p>2</p>
<p id= "BC" >3</P>
<p>4</p>
<ul>
<li>
<p>4</p>
</li>
<li>
<p>5</p>
</li>
<li>
<p>6</p>
</li>
</ul>
</body>


Structure pseudo-Class selector
Tags: first-child{}: First of the tag, the first child element in the parent element
<title>first-child</title>
<style type= "Text/css" >
p:first-child{
Background-color: #0F0;
}
</style>

<body>
<p> father softly I'm gone,
As I come softly;
I waved softly,
Goodbye to the clouds of the Western heavens. </p>
<div>
<p>1
The golden Willow on the river
Is the bride in the sunset
The vivid shadows in the waves,
Ripples in my heart. </p>
<p>2
A dream? To support a long pole,
To the green grass,
Full of a ship's star-shining,
Singing in the Splendor of the Stars
</p>
</div>
</body>

Tags: last-child{}: Last this tag, matching the last child element in the parent element
<title>last-child</title>
<style type= "Text/css" >
p:last-child{
Background-color: #C0F;
}
</style>

<body>
<p> I am a cloud in the sky,
Occasionally projected on your wave heart--
You don't have to be surprised,</p>
<p> no need to be happy--
The traces were wiped out in a twinkling. </p>
<p> you and I meet in the sea of night,
You have yours, I have mine, the direction;</p>
<p> You remember it,
You better forget it.
, in the intersection of the light of each other! </p>
</body>

Tags: nth-child{n}: Nth the label, matching the nth child element in a parent class element
n can be a number, a keyword, or a formula
<title>nth-child</title>
<style type= "Text/css" >
P:nth-child (2) {
Background-color: #0F0;
}

</style>

<body>
<p> I am a cloud in the sky,
Occasionally projected on your wave heart--
You don't have to be surprised,</p>
<p> no need to be happy--
The traces were wiped out in a twinkling. </p>
<p> you and I meet in the sea of night,
You have yours, I have mine, the direction;</p>
<p> You remember it,
You better forget it.
, in the intersection of the light of each other! </p>
</body>

4th Chapter CSS3

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.