SlideShare une entreprise Scribd logo
1  sur  16
Télécharger pour lire hors ligne
Style CSS and Selector
By Yaowaluck Promdee, Sumonta Kasemvilas
322432 Web Design Technology
Computer Science Khon Kaen University
HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR ASSIGNMENT
WDS
CS KKU
(C) Web Design Technology 2015 1
Index
•  CSS Basic
•  CSS Syntax
•  How to use Style Sheet
•  Selectors
•  Assignment
HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR
WDS
CS KKU
(C) Web Design Technology 2015 2
ASSIGNMENT
HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR
WDS
CS KKU
What is CSS?
Single Source of HTML
Web Browser
Other Media
Print Output
Server
Clients
Formatting data for multiple destination
Cascading Style Sheets (CSS) is a style
sheet language used for describing
the look and formatting of a document
written in a markup language.
CSS Style Sheet
(C) Web Design Technology 2015 3
CSS BASIC > WHAT IS CSS
ASSIGNMENT
HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR
WDS
CS KKU
http://ryanstutorials.net/css-tutorial/img/css_flexibility.png
CSS is
a language for describing the look and formatting of
content.
The selector identifies which parts of the content the
rules should apply to. The rules that are inside the
opening and closing curly brackets ( { } ) are applied
to any items matching the selector.
selector {
property: value;
property: value; }
/* This is comments */
(C) Web Design Technology 2015 4
CSS BASIC > CSS IS A
ASSIGNMENT
HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR
WDS
CS KKU
(C) Web Design Technology 2015 5
selector { property:value }
selector { property1:value1; property2:value2 }
h1 { color:red; font-size:12px; }
Selector Declaration
Property PropertyValue Value
ASSIGNMENT
HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR
WDS
CS KKU
(C) Web Design Technology 2015 6
Three Ways to Insert CSS
1.  Inline Style
2. Internal Style Sheet
3. External Style Sheet
How to inserting a style sheet
ASSIGNMENT
HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR
WDS
CS KKU
(C) Web Design Technology 2015 7
1. Inline Style
HOW TO > INLINE STYLE
Example
<!DOCTYPE html>
<html>
<body>
<h1 style="color:blue;margin-left:30px;">This is a
heading.</h1>
<p>This is a paragraph.</p>
</body>
</html>
An inline style may be used to
apply a unique style for a single
element.
An inline style loses many of the
advantages of a style sheet (by
mixing content with presentation).
Use this method sparingly
<Tag style="property:value;">
ASSIGNMENT
HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR
WDS
CS KKU
(C) Web Design Technology 2015 8
2. Internal Style sheet
HOW TO > INTERNAL STYLE SHEET
<style type="text/css">
<!--selector {property1: value1; property2: value2}... -->
</style>
An internal style sheet should be used when a single document has a unique style.
You define internal styles in the head section of an HTML page, inside the <style>
tag
body { background-color: linen; }
h1 { color: maroon; margin-left: 40px; }
ASSIGNMENT
HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR
WDS
CS KKU
(C) Web Design Technology 2015 9
3. External Style sheet
HOW TO > EXTERNAL STYLE SHEET
<link rel="stylesheet" type="text/css" href="URL file.css">
<!DOCTYPE html><html> <head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body> </body> </html>
An external style sheet is ideal when the style is applied to many pages. With an external
style sheet, you can change the look of an entire Web site by changing just one file.
Each page must include a link to the style sheet with the <link> tag. The <link> tag goes
inside the head section:
ASSIGNMENT
HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR
WDS
CS KKU
(C) Web Design Technology 2015 10
CSS Selector
SELECTOR > CSS SELECTOR
Element Selector ID Selector Class Selector
ASSIGNMENT
HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR
WDS
CS KKU
(C) Web Design Technology 2015 11
SELECTOR > CSS SELECTOR > ELEMENT SELECTOR
The element selector selects elements based on the element name.
1. Element Selector
p {
    text-align: center;
    color: red;
}
<p>Example1</p>
<h1>Example2</h1>
<p>Example3</p>
Result
---------------------------------------
Example1
Example2
Example3
ASSIGNMENT
HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR
WDS
CS KKU
(C) Web Design Technology 2015 12
SELECTOR > CSS SELECTOR > ID SELECTOR
2. ID Selector
The id selector uses the id attribute of an HTML tag to find the specific element.
An id should be unique within a page, so you should use the id selector when you
want to find a single, unique element.
#paragraph {
    text-align: center;
    color: red;
}
<p id="paragraph">Hello World!</p>
<p>This paragraph is not affected by the
style.</p>
ASSIGNMENT
HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR
WDS
CS KKU
(C) Web Design Technology 2015 13
SELECTOR > CSS SELECTOR > CLASS SELECTOR
3. Class Selector
.center {
text-align: center;
color: red; }
<h1 class="center">sentence1</h1>
<p class="center">sentence2</p>
The class selector finds elements with the specific class.
The class selector uses the HTML class attribute.
To find elements with a specific class, write a period character, followed by the name of the
class:
ASSIGNMENT
HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR
WDS
CS KKU
(C) Web Design Technology 2015 14
ASSIGNMENT
Example 2
SELECTOR > CSS SELECTOR > CLASS SELECTOR > EXAMPLE
<h1>This is a heading</h1>
<h2>This is a smaller heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
How to write CSS?
Answer:
Try it!
Change the color of all <p> and <h1> elements, to “blue”, and h1 is bold font.
Group the selectors to minimize code.
HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR
WDS
CS KKU
(C) Web Design Technology 2015 15
ASSIGNMENT
Example Selector Class attribute
SELECTOR > CSS SELECTOR > CLASS SELECTOR > EXAMPLE
p.center {
text-align: center;
color: red;
font-weight:bold;
}
<h1 class="center">This heading </h1>
<p class="center">This paragraph will be red
and center-aligned.</p>
Try it!
HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR ASSIGNMENT
WDS
CS KKU
(C) Web Design Technology 2015 16
Assignment#5 Style and Selectors
Create a Webpage to present your two favorite movies
using CSS (eg. all selectors in class today: element, class,
id sector) and you must comment your own CSS code.
Grade will be based on your CSS technique and look and
feel of the Web page.

Contenu connexe

Tendances (20)

Navigation and Link
Navigation and LinkNavigation and Link
Navigation and Link
 
Good/Bad Web Design
Good/Bad Web DesignGood/Bad Web Design
Good/Bad Web Design
 
CSS Dasar #9 : Inheritance
CSS Dasar #9 : InheritanceCSS Dasar #9 : Inheritance
CSS Dasar #9 : Inheritance
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
Overview HTML, HTML5 and Validations
Overview HTML, HTML5 and Validations Overview HTML, HTML5 and Validations
Overview HTML, HTML5 and Validations
 
Css ppt
Css pptCss ppt
Css ppt
 
CSS Dasar #8 : Pseudo-class
CSS Dasar #8 : Pseudo-classCSS Dasar #8 : Pseudo-class
CSS Dasar #8 : Pseudo-class
 
CSS
CSSCSS
CSS
 
CSS Grid
CSS GridCSS Grid
CSS Grid
 
Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01
 
HTML
HTMLHTML
HTML
 
Introducing CSS Grid
Introducing CSS GridIntroducing CSS Grid
Introducing CSS Grid
 
CSS Best practice
CSS Best practiceCSS Best practice
CSS Best practice
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
 
CSS Dasar #3 : Penempatan CSS
CSS Dasar #3 : Penempatan CSSCSS Dasar #3 : Penempatan CSS
CSS Dasar #3 : Penempatan CSS
 
Cascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) helpCascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) help
 
CSS Dasar #5 : Text Styling
CSS Dasar #5 : Text StylingCSS Dasar #5 : Text Styling
CSS Dasar #5 : Text Styling
 
Page layouts flexible and fixed layout with CSS
Page layouts flexible and fixed layout with CSSPage layouts flexible and fixed layout with CSS
Page layouts flexible and fixed layout with CSS
 
Bootstrap Framework
Bootstrap Framework Bootstrap Framework
Bootstrap Framework
 
Page layout with css
Page layout with cssPage layout with css
Page layout with css
 

Similaire à Style and Selector

Similaire à Style and Selector (20)

Css.html
Css.htmlCss.html
Css.html
 
Style and Selector Part2
Style and Selector Part2Style and Selector Part2
Style and Selector Part2
 
Css training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentialsCss training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentials
 
Lecture-6.pptx
Lecture-6.pptxLecture-6.pptx
Lecture-6.pptx
 
Lecture 3CSS part 1.pptx
Lecture 3CSS part 1.pptxLecture 3CSS part 1.pptx
Lecture 3CSS part 1.pptx
 
New Css style
New Css styleNew Css style
New Css style
 
Chapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssChapter 4a cascade style sheet css
Chapter 4a cascade style sheet css
 
INTRODUCTIONS OF CSS
INTRODUCTIONS OF CSSINTRODUCTIONS OF CSS
INTRODUCTIONS OF CSS
 
Css
CssCss
Css
 
Css
CssCss
Css
 
IP - Lecture 6, 7 Chapter-3 (3).ppt
IP - Lecture 6, 7 Chapter-3 (3).pptIP - Lecture 6, 7 Chapter-3 (3).ppt
IP - Lecture 6, 7 Chapter-3 (3).ppt
 
Teaching presentation
Teaching presentationTeaching presentation
Teaching presentation
 
Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1
 
Lecture 9 CSS part 1.pptxType Classification
Lecture 9 CSS part 1.pptxType ClassificationLecture 9 CSS part 1.pptxType Classification
Lecture 9 CSS part 1.pptxType Classification
 
Web Designing
Web DesigningWeb Designing
Web Designing
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
 
Vskills certified css designer Notes
Vskills certified css designer NotesVskills certified css designer Notes
Vskills certified css designer Notes
 
CSC PPT 4.pptx
CSC PPT 4.pptxCSC PPT 4.pptx
CSC PPT 4.pptx
 
chitra
chitrachitra
chitra
 
David Weliver
David WeliverDavid Weliver
David Weliver
 

Plus de Yaowaluck Promdee (20)

A basic of UX for beginner
A basic of UX for beginnerA basic of UX for beginner
A basic of UX for beginner
 
TCAS 2563
TCAS 2563TCAS 2563
TCAS 2563
 
Portfolio design
Portfolio designPortfolio design
Portfolio design
 
Concept to creation story and storyboard
Concept to creation  story and storyboard Concept to creation  story and storyboard
Concept to creation story and storyboard
 
Observation and interviewing
Observation and interviewingObservation and interviewing
Observation and interviewing
 
Requirement gathering-and-lean-canvas
Requirement gathering-and-lean-canvasRequirement gathering-and-lean-canvas
Requirement gathering-and-lean-canvas
 
Good bad design
Good bad designGood bad design
Good bad design
 
Graphic, Color and tools
Graphic, Color and toolsGraphic, Color and tools
Graphic, Color and tools
 
HTML 5
HTML 5HTML 5
HTML 5
 
Web Interface
Web InterfaceWeb Interface
Web Interface
 
Game design
Game designGame design
Game design
 
Powerpoint
Powerpoint Powerpoint
Powerpoint
 
Program Interface
Program Interface Program Interface
Program Interface
 
Mobile Interface
Mobile Interface   Mobile Interface
Mobile Interface
 
Personas and scenario
Personas and scenarioPersonas and scenario
Personas and scenario
 
Ux design process
Ux design processUx design process
Ux design process
 
Graphic Design
Graphic Design Graphic Design
Graphic Design
 
Lab#2 illustrator
Lab#2 illustratorLab#2 illustrator
Lab#2 illustrator
 
Good/Bad Design
Good/Bad DesignGood/Bad Design
Good/Bad Design
 
Content management system
Content management systemContent management system
Content management system
 

Dernier

How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 

Dernier (20)

How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 

Style and Selector

  • 1. Style CSS and Selector By Yaowaluck Promdee, Sumonta Kasemvilas 322432 Web Design Technology Computer Science Khon Kaen University HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR ASSIGNMENT WDS CS KKU (C) Web Design Technology 2015 1
  • 2. Index •  CSS Basic •  CSS Syntax •  How to use Style Sheet •  Selectors •  Assignment HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR WDS CS KKU (C) Web Design Technology 2015 2 ASSIGNMENT
  • 3. HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR WDS CS KKU What is CSS? Single Source of HTML Web Browser Other Media Print Output Server Clients Formatting data for multiple destination Cascading Style Sheets (CSS) is a style sheet language used for describing the look and formatting of a document written in a markup language. CSS Style Sheet (C) Web Design Technology 2015 3 CSS BASIC > WHAT IS CSS ASSIGNMENT
  • 4. HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR WDS CS KKU http://ryanstutorials.net/css-tutorial/img/css_flexibility.png CSS is a language for describing the look and formatting of content. The selector identifies which parts of the content the rules should apply to. The rules that are inside the opening and closing curly brackets ( { } ) are applied to any items matching the selector. selector { property: value; property: value; } /* This is comments */ (C) Web Design Technology 2015 4 CSS BASIC > CSS IS A ASSIGNMENT
  • 5. HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR WDS CS KKU (C) Web Design Technology 2015 5 selector { property:value } selector { property1:value1; property2:value2 } h1 { color:red; font-size:12px; } Selector Declaration Property PropertyValue Value ASSIGNMENT
  • 6. HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR WDS CS KKU (C) Web Design Technology 2015 6 Three Ways to Insert CSS 1.  Inline Style 2. Internal Style Sheet 3. External Style Sheet How to inserting a style sheet ASSIGNMENT
  • 7. HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR WDS CS KKU (C) Web Design Technology 2015 7 1. Inline Style HOW TO > INLINE STYLE Example <!DOCTYPE html> <html> <body> <h1 style="color:blue;margin-left:30px;">This is a heading.</h1> <p>This is a paragraph.</p> </body> </html> An inline style may be used to apply a unique style for a single element. An inline style loses many of the advantages of a style sheet (by mixing content with presentation). Use this method sparingly <Tag style="property:value;"> ASSIGNMENT
  • 8. HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR WDS CS KKU (C) Web Design Technology 2015 8 2. Internal Style sheet HOW TO > INTERNAL STYLE SHEET <style type="text/css"> <!--selector {property1: value1; property2: value2}... --> </style> An internal style sheet should be used when a single document has a unique style. You define internal styles in the head section of an HTML page, inside the <style> tag body { background-color: linen; } h1 { color: maroon; margin-left: 40px; } ASSIGNMENT
  • 9. HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR WDS CS KKU (C) Web Design Technology 2015 9 3. External Style sheet HOW TO > EXTERNAL STYLE SHEET <link rel="stylesheet" type="text/css" href="URL file.css"> <!DOCTYPE html><html> <head> <link rel="stylesheet" type="text/css" href="mystyle.css"> </head> <body> </body> </html> An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can change the look of an entire Web site by changing just one file. Each page must include a link to the style sheet with the <link> tag. The <link> tag goes inside the head section: ASSIGNMENT
  • 10. HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR WDS CS KKU (C) Web Design Technology 2015 10 CSS Selector SELECTOR > CSS SELECTOR Element Selector ID Selector Class Selector ASSIGNMENT
  • 11. HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR WDS CS KKU (C) Web Design Technology 2015 11 SELECTOR > CSS SELECTOR > ELEMENT SELECTOR The element selector selects elements based on the element name. 1. Element Selector p {     text-align: center;     color: red; } <p>Example1</p> <h1>Example2</h1> <p>Example3</p> Result --------------------------------------- Example1 Example2 Example3 ASSIGNMENT
  • 12. HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR WDS CS KKU (C) Web Design Technology 2015 12 SELECTOR > CSS SELECTOR > ID SELECTOR 2. ID Selector The id selector uses the id attribute of an HTML tag to find the specific element. An id should be unique within a page, so you should use the id selector when you want to find a single, unique element. #paragraph {     text-align: center;     color: red; } <p id="paragraph">Hello World!</p> <p>This paragraph is not affected by the style.</p> ASSIGNMENT
  • 13. HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR WDS CS KKU (C) Web Design Technology 2015 13 SELECTOR > CSS SELECTOR > CLASS SELECTOR 3. Class Selector .center { text-align: center; color: red; } <h1 class="center">sentence1</h1> <p class="center">sentence2</p> The class selector finds elements with the specific class. The class selector uses the HTML class attribute. To find elements with a specific class, write a period character, followed by the name of the class: ASSIGNMENT
  • 14. HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR WDS CS KKU (C) Web Design Technology 2015 14 ASSIGNMENT Example 2 SELECTOR > CSS SELECTOR > CLASS SELECTOR > EXAMPLE <h1>This is a heading</h1> <h2>This is a smaller heading</h2> <p>This is a paragraph.</p> <p>This is another paragraph.</p> How to write CSS? Answer: Try it! Change the color of all <p> and <h1> elements, to “blue”, and h1 is bold font. Group the selectors to minimize code.
  • 15. HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR WDS CS KKU (C) Web Design Technology 2015 15 ASSIGNMENT Example Selector Class attribute SELECTOR > CSS SELECTOR > CLASS SELECTOR > EXAMPLE p.center { text-align: center; color: red; font-weight:bold; } <h1 class="center">This heading </h1> <p class="center">This paragraph will be red and center-aligned.</p> Try it!
  • 16. HOME INDEX CSS BASIC CSS SYNTAX HOW TO SELECTOR ASSIGNMENT WDS CS KKU (C) Web Design Technology 2015 16 Assignment#5 Style and Selectors Create a Webpage to present your two favorite movies using CSS (eg. all selectors in class today: element, class, id sector) and you must comment your own CSS code. Grade will be based on your CSS technique and look and feel of the Web page.