SlideShare ist ein Scribd-Unternehmen logo
1 von 9
CSS Syntax & Selector
Mark Chen

2/13/2014

1
CSS Syntax
•

A CSS rule has two main parts: a selector, and one or more declarations:

•

The selector is normally the HTML element you want to style.

•

Each declaration consists of a property and a value.

•

The property is the style attribute you want to change. Each property has a value.

2/13/2014

2
CSS Selectors
Selector

Example

Example description

CSS

.class

.intro

Selects all elements with class="intro"

1

#id

#firstname

Selects the element with id="firstname"

1

*

*

Selects all elements

2

element

p

Selects all <p> elements

1

element,element

div,p

Selects all <div> elements and all <p> elements

1

element element

div p

Selects all <p> elements inside <div> elements

1

element>element

div>p

Selects all <p> elements where the parent is a <div>
element

2

element+element

div+p

Selects all <p> elements that are placed immediately after 2
<div> elements

2/13/2014

3
Attribute Selectors
Selector

Example

Example description

CSS

[attribute]

[target]

Selects all elements with a target attribute

2

[attribute=value]

[target=_blank]

Selects all elements with target="_blank"

2

[attribute~=value]

[title~=flower]

Selects all elements with a title attribute containing the 2
word "flower"

[attribute|=value]

[lang|=en]

Selects all elements with a lang attribute value starting 2
with "en"

[attribute^=value]

a[src^="https"]

Selects every <a> element whose src attribute value
begins with "https"

3

[attribute$=value]

a[src$=".pdf"]

Selects every <a> element whose src attribute value
ends with ".pdf"

3

[attribute*=value]

a[src*="w3schools"] Selects every <a> element whose src attribute value
contains the substring "w3schools"

3

2/13/2014

4
CSS Selectors
Selector

Example

Example description

CSS

:before

p:before

Insert content before the content of every <p> element

2

:after

p:after

Insert content after every <p> element

2

:first-child

p:first-child

Selects every <p> element that is the first child of its parent

2

:last-child

p:last-child

Selects every <p> element that is the last child of its parent

3

:nth-child(n)

p:nth-child(2)

Selects every <p> element that is the second child of its parent

3

:nth-last-child(n)

p:nth-last-child(2)

Selects every <p> element that is the second child of its parent,
counting from the last child

3

:nth-of-type(n)

p:nth-of-type(2)

Selects every <p> element that is the second <p> element of its
parent

3

:nth-last-of-type(n)

p:nth-last-of-type(2)

Selects every <p> element that is the second <p> element of its
parent, counting from the last child

3

2/13/2014

5
The CSS Box Model

總寬度的計算:

250px (width)
+ 20px (left + right padding)
+ 10px (left + right border)
+ 20px (left + right margin)
---------------------------------= 300px
2/13/2014

The margin property can have from one to four values.
 margin:25px 50px 75px 100px;
上
右
下
左
 margin:25px 50px 75px;
上
左&右 下
 margin:25px 50px;
上&下 左&右
 margin:25px;
上&下&左&右

6
讓 div 以 ol, ul, li 的樣式呈現
Can work on IE, Chrome

2/13/2014

But not work on firefox

7
:after or :before - content
Can work on Chrome, firefox, IE

Note: For :before or :after to work in IE8, a <!DOCTYPE> must be declared.
2/13/2014

8
Reference
•

W3Schools - CSS Syntax
•

•

W3Schools - CSS Selector Reference
•

•

http://www.w3schools.com/css/css_syntax.asp
http://www.w3schools.com/cssref/css_selectors.asp

W3Schools - The CSS Box Model
•

http://www.w3schools.com/css/css_boxmodel.asp

2/13/2014

9

Weitere ähnliche Inhalte

Ähnlich wie Mark css syntax & selector

TAppWeb Training Material
TAppWeb Training MaterialTAppWeb Training Material
TAppWeb Training MaterialArvie Bernal
 
TApp Documentation
TApp DocumentationTApp Documentation
TApp DocumentationArvie Bernal
 
jQuery BootCamp : Creating the Wrapped Element Set
jQuery BootCamp : Creating the Wrapped Element SetjQuery BootCamp : Creating the Wrapped Element Set
jQuery BootCamp : Creating the Wrapped Element SetWildan Maulana
 
J Query Introduction And JQuery Selectors
J Query Introduction And JQuery SelectorsJ Query Introduction And JQuery Selectors
J Query Introduction And JQuery SelectorsAnand Kumar Rajana
 
CSS for Developers
CSS for DevelopersCSS for Developers
CSS for DevelopersNascenia IT
 
JQUERY EXAMPLE for Web Developer (Video Training Tutorial)
JQUERY EXAMPLE for Web Developer (Video Training Tutorial)JQUERY EXAMPLE for Web Developer (Video Training Tutorial)
JQUERY EXAMPLE for Web Developer (Video Training Tutorial)Kaml Sah
 
Jquery Example PPT
Jquery Example PPTJquery Example PPT
Jquery Example PPTKaml Sah
 
VISUAL CHEAT SHEET
VISUAL CHEAT SHEETVISUAL CHEAT SHEET
VISUAL CHEAT SHEETDanilo Sousa
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfnitinarora01
 
Specificity and CSS Selectors
Specificity and CSS SelectorsSpecificity and CSS Selectors
Specificity and CSS Selectorspalomateach
 
CSS Pseudo Elements.pdf
CSS Pseudo Elements.pdfCSS Pseudo Elements.pdf
CSS Pseudo Elements.pdfsonu kumar
 
J query 1.7 cheat sheet
J query 1.7 cheat sheetJ query 1.7 cheat sheet
J query 1.7 cheat sheetmaamir farooq
 
J query 17-visual-cheat-sheet1
J query 17-visual-cheat-sheet1J query 17-visual-cheat-sheet1
J query 17-visual-cheat-sheet1sdcasas
 
Real Browser Check Scripting Guide - Rigor Monitoring
Real Browser Check Scripting Guide - Rigor MonitoringReal Browser Check Scripting Guide - Rigor Monitoring
Real Browser Check Scripting Guide - Rigor MonitoringAnthony Ferrari
 
Introduction to Html5, css, Javascript and Jquery
Introduction to Html5, css, Javascript and JqueryIntroduction to Html5, css, Javascript and Jquery
Introduction to Html5, css, Javascript and Jqueryvaluebound
 

Ähnlich wie Mark css syntax & selector (20)

TAppWeb Training Material
TAppWeb Training MaterialTAppWeb Training Material
TAppWeb Training Material
 
TApp Documentation
TApp DocumentationTApp Documentation
TApp Documentation
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
 
Jquery for Beginners
Jquery for BeginnersJquery for Beginners
Jquery for Beginners
 
jQuery BootCamp : Creating the Wrapped Element Set
jQuery BootCamp : Creating the Wrapped Element SetjQuery BootCamp : Creating the Wrapped Element Set
jQuery BootCamp : Creating the Wrapped Element Set
 
J Query Introduction And JQuery Selectors
J Query Introduction And JQuery SelectorsJ Query Introduction And JQuery Selectors
J Query Introduction And JQuery Selectors
 
CSS for Developers
CSS for DevelopersCSS for Developers
CSS for Developers
 
Lab#5 style and selector
Lab#5 style and selectorLab#5 style and selector
Lab#5 style and selector
 
JQUERY EXAMPLE for Web Developer (Video Training Tutorial)
JQUERY EXAMPLE for Web Developer (Video Training Tutorial)JQUERY EXAMPLE for Web Developer (Video Training Tutorial)
JQUERY EXAMPLE for Web Developer (Video Training Tutorial)
 
Jquery Example PPT
Jquery Example PPTJquery Example PPT
Jquery Example PPT
 
Basic Details of HTML and CSS.pdf
Basic Details of HTML and CSS.pdfBasic Details of HTML and CSS.pdf
Basic Details of HTML and CSS.pdf
 
VISUAL CHEAT SHEET
VISUAL CHEAT SHEETVISUAL CHEAT SHEET
VISUAL CHEAT SHEET
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdf
 
Specificity and CSS Selectors
Specificity and CSS SelectorsSpecificity and CSS Selectors
Specificity and CSS Selectors
 
CSS Pseudo Elements.pdf
CSS Pseudo Elements.pdfCSS Pseudo Elements.pdf
CSS Pseudo Elements.pdf
 
J query 1.7 cheat sheet
J query 1.7 cheat sheetJ query 1.7 cheat sheet
J query 1.7 cheat sheet
 
J query 17-visual-cheat-sheet1
J query 17-visual-cheat-sheet1J query 17-visual-cheat-sheet1
J query 17-visual-cheat-sheet1
 
Real Browser Check Scripting Guide - Rigor Monitoring
Real Browser Check Scripting Guide - Rigor MonitoringReal Browser Check Scripting Guide - Rigor Monitoring
Real Browser Check Scripting Guide - Rigor Monitoring
 
Xml
XmlXml
Xml
 
Introduction to Html5, css, Javascript and Jquery
Introduction to Html5, css, Javascript and JqueryIntroduction to Html5, css, Javascript and Jquery
Introduction to Html5, css, Javascript and Jquery
 

Mehr von LearningTech

Mehr von LearningTech (20)

vim
vimvim
vim
 
PostCss
PostCssPostCss
PostCss
 
ReactJs
ReactJsReactJs
ReactJs
 
Docker
DockerDocker
Docker
 
Semantic ui
Semantic uiSemantic ui
Semantic ui
 
node.js errors
node.js errorsnode.js errors
node.js errors
 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejs
 
Expression tree
Expression treeExpression tree
Expression tree
 
SQL 效能調校
SQL 效能調校SQL 效能調校
SQL 效能調校
 
flexbox report
flexbox reportflexbox report
flexbox report
 
Vic weekly learning_20160504
Vic weekly learning_20160504Vic weekly learning_20160504
Vic weekly learning_20160504
 
Reflection &amp; activator
Reflection &amp; activatorReflection &amp; activator
Reflection &amp; activator
 
Peggy markdown
Peggy markdownPeggy markdown
Peggy markdown
 
Node child process
Node child processNode child process
Node child process
 
20160415ken.lee
20160415ken.lee20160415ken.lee
20160415ken.lee
 
Peggy elasticsearch應用
Peggy elasticsearch應用Peggy elasticsearch應用
Peggy elasticsearch應用
 
Expression tree
Expression treeExpression tree
Expression tree
 
Vic weekly learning_20160325
Vic weekly learning_20160325Vic weekly learning_20160325
Vic weekly learning_20160325
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
 
git command
git commandgit command
git command
 

Kürzlich hochgeladen

DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Kürzlich hochgeladen (20)

DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

Mark css syntax & selector

  • 1. CSS Syntax & Selector Mark Chen 2/13/2014 1
  • 2. CSS Syntax • A CSS rule has two main parts: a selector, and one or more declarations: • The selector is normally the HTML element you want to style. • Each declaration consists of a property and a value. • The property is the style attribute you want to change. Each property has a value. 2/13/2014 2
  • 3. CSS Selectors Selector Example Example description CSS .class .intro Selects all elements with class="intro" 1 #id #firstname Selects the element with id="firstname" 1 * * Selects all elements 2 element p Selects all <p> elements 1 element,element div,p Selects all <div> elements and all <p> elements 1 element element div p Selects all <p> elements inside <div> elements 1 element>element div>p Selects all <p> elements where the parent is a <div> element 2 element+element div+p Selects all <p> elements that are placed immediately after 2 <div> elements 2/13/2014 3
  • 4. Attribute Selectors Selector Example Example description CSS [attribute] [target] Selects all elements with a target attribute 2 [attribute=value] [target=_blank] Selects all elements with target="_blank" 2 [attribute~=value] [title~=flower] Selects all elements with a title attribute containing the 2 word "flower" [attribute|=value] [lang|=en] Selects all elements with a lang attribute value starting 2 with "en" [attribute^=value] a[src^="https"] Selects every <a> element whose src attribute value begins with "https" 3 [attribute$=value] a[src$=".pdf"] Selects every <a> element whose src attribute value ends with ".pdf" 3 [attribute*=value] a[src*="w3schools"] Selects every <a> element whose src attribute value contains the substring "w3schools" 3 2/13/2014 4
  • 5. CSS Selectors Selector Example Example description CSS :before p:before Insert content before the content of every <p> element 2 :after p:after Insert content after every <p> element 2 :first-child p:first-child Selects every <p> element that is the first child of its parent 2 :last-child p:last-child Selects every <p> element that is the last child of its parent 3 :nth-child(n) p:nth-child(2) Selects every <p> element that is the second child of its parent 3 :nth-last-child(n) p:nth-last-child(2) Selects every <p> element that is the second child of its parent, counting from the last child 3 :nth-of-type(n) p:nth-of-type(2) Selects every <p> element that is the second <p> element of its parent 3 :nth-last-of-type(n) p:nth-last-of-type(2) Selects every <p> element that is the second <p> element of its parent, counting from the last child 3 2/13/2014 5
  • 6. The CSS Box Model 總寬度的計算: 250px (width) + 20px (left + right padding) + 10px (left + right border) + 20px (left + right margin) ---------------------------------= 300px 2/13/2014 The margin property can have from one to four values.  margin:25px 50px 75px 100px; 上 右 下 左  margin:25px 50px 75px; 上 左&右 下  margin:25px 50px; 上&下 左&右  margin:25px; 上&下&左&右 6
  • 7. 讓 div 以 ol, ul, li 的樣式呈現 Can work on IE, Chrome 2/13/2014 But not work on firefox 7
  • 8. :after or :before - content Can work on Chrome, firefox, IE Note: For :before or :after to work in IE8, a <!DOCTYPE> must be declared. 2/13/2014 8
  • 9. Reference • W3Schools - CSS Syntax • • W3Schools - CSS Selector Reference • • http://www.w3schools.com/css/css_syntax.asp http://www.w3schools.com/cssref/css_selectors.asp W3Schools - The CSS Box Model • http://www.w3schools.com/css/css_boxmodel.asp 2/13/2014 9