SlideShare a Scribd company logo
1 of 42
Cascading Style Sheets
                          UC Berkeley Graduate School of Journalism




Tuesday, March 15, 2011
CSS fundamentals

                    • CSS is for styling an HTML document.
                    • CSS can affect fonts, sizes, colors,
                          backgrounds, spacing, borders, and more.
                    • CSS is its own language, with its own syntax.


Tuesday, March 15, 2011
Where is CSS kept?



Tuesday, March 15, 2011
One of three ways

                    1. Loaded in a separate document.
                    2. Specified in the <head> tag of the HTML
                       document.
                    3. Specified directly in the HTML tags
                       themselves.



Tuesday, March 15, 2011
One of three ways

                    • External Style Sheets
                    • Embedded Style Sheets
                    • Inline Style Sheets


Tuesday, March 15, 2011
External Style Sheets
                <head	
  lang="en">

                	
  	
  <meta	
  charset="utf-­‐8">

                	
  	
  <title>This	
  is	
  my	
  title</title>

                	
  	
  <meta	
  name="description"	
  content="This	
  is	
  an	
  example	
  of	
  my	
  webpage">

                	
  	
  <meta	
  name="author"	
  content="Jeremy	
  Rue">

                	
  	
  <link	
  rel="stylesheet"	
  href="css/style.css">

                </head>




Tuesday, March 15, 2011
External Style Sheets
                    • The best way to include CSS in a
                          document.
                    • The only drawback (and it’s a small one) is
                          that if the style sheet is separate, therefore
                          if it ever gets deleted then the page won’t
                          look right.
                    • Most general method of including styles.
Tuesday, March 15, 2011
Embedded Styles
                <head	
  lang="en">

                          <meta	
  charset="utf-­‐8">

                          <title>This	
  is	
  my	
  title</title>	
  

                          <style	
  type="text/css">

                              h1	
  {color:red}

                              p	
  {color:blue}

                          </style>

                </head>




Tuesday, March 15, 2011
Embedded Styles
                    • Will override any similar rules from
                          external style sheets.
                    • Sometimes this is used because you want a
                          single page to have some different styles
                          that the rest of your website.
                    • Styles stay with the HTML page, because it’s
                          a part of the page.


Tuesday, March 15, 2011
Inline Styles

                <body>
                          <header>
                           <h1	
  style=“color:red”>Hello	
  World</h1>
                          </header>
                </body>




Tuesday, March 15, 2011
Inline Styles
                    • The worst way to include CSS in a
                          document. Avoid if possible.

                    • Sometimes it can be needed, because you
                          are working in a system where you just
                          need one specific element, in a single
                          webpage, to look a certain way and you
                          don’t have access to the style sheets.


Tuesday, March 15, 2011
Syntax



Tuesday, March 15, 2011
Parts of CSS element

                body	
  {
                          font-­‐size:	
  12px;
                          color:	
  #000000;
                }




Tuesday, March 15, 2011
Parts of CSS element

                body	
  {
                          font-­‐size:	
  12px;
                          color:	
  #000000;
                }

               This is the SELECTOR. It is specifying the part
                 of the page that will be affected by the style.
Tuesday, March 15, 2011
Parts of CSS element

                body	
  {
                          font-­‐size:	
  12px;
                          color:	
  #000000;
                }

                These are PROPERTIES. There are a number
                  of defined properties that you can change.
Tuesday, March 15, 2011
Parts of CSS element

                body	
  {
                          font-­‐size:	
  12px;
                          color:	
  #000000;
                }


                           These are VALUES of the property.
Tuesday, March 15, 2011
Parts of CSS element

                body	
  {
                          font-­‐size:	
  12px;
                          color:	
  #000000;
                }

                                A COLON separates the
                                properties from the values.
Tuesday, March 15, 2011
Parts of CSS element

                body	
  {
                          font-­‐size:	
  12px;
                          color:	
  #000000;
                }


                          A SEMI-COLON ends each line of code.
Tuesday, March 15, 2011
Parts of CSS element

                body	
  {
                          font-­‐size:	
  12px;
                          color:	
  #000000;
                }

                   Note the CURLY BRACKETS, one opens
                             and the other closes.
Tuesday, March 15, 2011
font-family
                    • Specifies a family of fonts to use. Create a
                          list of fallbacks should the user not have the
                          font installed.
                    • Put font names with more than one word
                          in quotes.
                    • Example:
                          font-­‐family:“Times	
  New	
  Roman”,	
  Times,	
  serif



Tuesday, March 15, 2011
color
                    • Specifies the color of text.
                    • Specify one of three ways: Hexadecimal,
                          RGB or simple names. We will use
                          hexadecimal.
                    • Example:
                          color:#aaf999


Tuesday, March 15, 2011
font-size
                    • You should use either px or em.
                    • PX stands for pixels, and is a fixed font size
                          in Internet Explorer.
                    • EM is a relative size, and is based on the
                          default font size of the browser.
                    • 1 em = 16 px in most browsers.
                    • font pixels/16 = the size you want.
Tuesday, March 15, 2011
EXAMPLE

                body	
  {
                          font-­‐family:“Palatino	
  Linotype”,	
  
                          “Book	
  Antiqua”,	
  Palatino,	
  serif;
                          color:	
  #eeeeee;
                }




Tuesday, March 15, 2011
background-color

                    • Specifies the background color of an
                          element using the same color units as
                          color. We use hexadecimal.
                    • Example:
                          background-­‐color:	
  #f5f5f5;



Tuesday, March 15, 2011
Base Styles
                    • Base styles means when you apply a
                          style to an element, like h1, h2 or p.
                    • Applies to that element throughout the
                          document.
                    • Example:
                          h1	
  {
                          	
  	
  	
  font-­‐family:	
  Helvetica,	
  Arial,	
  sans-­‐serif;
                          }


Tuesday, March 15, 2011
Grouping (selectors)

                    • If you want to apply a style to multiple
                          elements, use a comma.
                    • Example:
                          h1,	
  h2,	
  h3	
  {
                          	
  	
  	
  font-­‐family:	
  Helvetica,	
  Arial,	
  sans-­‐serif;
                          }




Tuesday, March 15, 2011
Nested (Selectors)
                    • If several base elements are listed with a
                          space, it means only elements that are
                          descendants of the first element.
                    • Example:
                          article	
  h1{
                          	
  	
  	
  	
  	
  	
  font-­‐size:	
  1.2	
  em;
                          }


Tuesday, March 15, 2011
IDs vs Classes



Tuesday, March 15, 2011
IDs and Classes

                    • IDs allow you specify specific elements in
                          an HTML document. Each ID can only be
                          specified once.
                    • Classes allow you to specify a group of
                          elements in an HTML document.You can
                          use a class an unlimited number of times.



Tuesday, March 15, 2011
IDs
                    • Each unique ID can be applied only once
                          to a document.
                    • HTML attribute example:
                          	
  id=“copyright”	
  

                    • CSS example:
                          #copyright	
  {
                          	
  	
  	
  font-­‐style:italic;
                          }
Tuesday, March 15, 2011
Classes
                    • Classes can apply to any number of
                          elements. Use classes to group elements to
                          your own grouping method.
                    • HTML example:
                          class=“headlines”

                    •     CSS	
  example:

                          .headlines	
  {
                          	
  	
  	
  	
  	
  font-­‐size:	
  1.2em;
                          }
Tuesday, March 15, 2011
Selectors
                    • There are lots of ways to specify the
                          elements you are trying to style.
                    • The most common: 1) base style 2)
                          descendants 3) IDs/classes

                          h2	
  {	
  color:#000000;	
  }

                          h2	
  p	
  {	
  color:#000000;	
  }

                          #firstpost	
  {	
  color:#000000;}
Tuesday, March 15, 2011
CSS Box Model



Tuesday, March 15, 2011
The Box Model

                <div	
  id=“content”>
                          <p>Some	
  content	
  inside	
  the	
  box</p>
                </div>




Tuesday, March 15, 2011
Tuesday, March 15, 2011
The Box Model

                    •     Margin - Clears an area around the border. The
                          margin does not have a background color, it is
                          completely transparent

                    •     Border - A border that goes around the padding
                          and content.

                    •     Padding - Clears an area around the content.

                    •     Content - The content of the box, where text
                          and images appear


Tuesday, March 15, 2011
The Box Model
                    • A DIV’s default height is defined by it’s
                          content.
                    • A DIV’s default width is defined by it’s
                          parent’s width.
                    • When width and height are defined, the
                          content will “overflow” if it’s larger than
                          the size of the box.


Tuesday, March 15, 2011
The Box Model
                #content	
  {
                          border:	
  10px	
  solid	
  #98bf21;
                          margin:	
  15px;
                          padding:	
  10px;
                          width:	
  300px;
                          height:	
  300px;
                }
Tuesday, March 15, 2011
250 px




Tuesday, March 15, 2011
Box Model


                The width and height properties only define the
                size of the content area.




Tuesday, March 15, 2011
Assignment: Cookie Recipe
                    1. Find a cookie recipe online. Anything will do.
                    2. Include a photo, ingredients and directions
                       and headline.
                    3. Make sure you style the:
                          i. Fonts
                          ii. Colors
                          iii. And group it all in a box

Tuesday, March 15, 2011
Tuesday, March 15, 2011

More Related Content

What's hot (20)

Css notes
Css notesCss notes
Css notes
 
Ifi7174 lesson2
Ifi7174 lesson2Ifi7174 lesson2
Ifi7174 lesson2
 
Ifi7174 lesson1
Ifi7174 lesson1Ifi7174 lesson1
Ifi7174 lesson1
 
Html
HtmlHtml
Html
 
Html.ppt
Html.pptHtml.ppt
Html.ppt
 
CSS notes
CSS notesCSS notes
CSS notes
 
Css
CssCss
Css
 
CSS: a rapidly changing world
CSS: a rapidly changing worldCSS: a rapidly changing world
CSS: a rapidly changing world
 
Css
CssCss
Css
 
Wp unit III
Wp unit IIIWp unit III
Wp unit III
 
Wp unit 1 (1)
Wp  unit 1 (1)Wp  unit 1 (1)
Wp unit 1 (1)
 
Styling Your Web Pages with Cascading Style Sheets / EDU course / University ...
Styling Your Web Pages with Cascading Style Sheets / EDU course / University ...Styling Your Web Pages with Cascading Style Sheets / EDU course / University ...
Styling Your Web Pages with Cascading Style Sheets / EDU course / University ...
 
Css Complete Notes
Css Complete NotesCss Complete Notes
Css Complete Notes
 
Dbms keysppt
Dbms keyspptDbms keysppt
Dbms keysppt
 
WEB and FONTS
WEB and FONTSWEB and FONTS
WEB and FONTS
 
Html
HtmlHtml
Html
 
Html
HtmlHtml
Html
 
What is CSS?
What is CSS?What is CSS?
What is CSS?
 
CSS Basics part One
CSS Basics part OneCSS Basics part One
CSS Basics part One
 
Responsive web design with html5 and css3
Responsive web design with html5 and css3Responsive web design with html5 and css3
Responsive web design with html5 and css3
 

Similar to CSS Fundamentals: External, Embedded & Inline Styles

Similar to CSS Fundamentals: External, Embedded & Inline Styles (20)

Intro to HTML
Intro to HTMLIntro to HTML
Intro to HTML
 
Css 1. -_introduction_2010-11_
Css 1. -_introduction_2010-11_Css 1. -_introduction_2010-11_
Css 1. -_introduction_2010-11_
 
Class13
Class13Class13
Class13
 
Lecture-7.pptx
Lecture-7.pptxLecture-7.pptx
Lecture-7.pptx
 
GTU Web Designing Interview Questions And Answers for freshers
GTU Web Designing Interview Questions And Answers for freshersGTU Web Designing Interview Questions And Answers for freshers
GTU Web Designing Interview Questions And Answers for freshers
 
basic programming language AND HTML CSS JAVApdf
basic programming language AND HTML CSS JAVApdfbasic programming language AND HTML CSS JAVApdf
basic programming language AND HTML CSS JAVApdf
 
CSS.pptx
CSS.pptxCSS.pptx
CSS.pptx
 
00 introduction
00 introduction00 introduction
00 introduction
 
BITM3730 10-31.pptx
BITM3730 10-31.pptxBITM3730 10-31.pptx
BITM3730 10-31.pptx
 
BITM3730 10-18.pptx
BITM3730 10-18.pptxBITM3730 10-18.pptx
BITM3730 10-18.pptx
 
DHTML
DHTMLDHTML
DHTML
 
Introduction to HTML
Introduction to HTMLIntroduction to HTML
Introduction to HTML
 
Css
CssCss
Css
 
HTML Bootcamp
HTML BootcampHTML Bootcamp
HTML Bootcamp
 
Html presentation
Html presentationHtml presentation
Html presentation
 
Episode 14 - Basics of HTML for Salesforce
Episode 14 - Basics of HTML for SalesforceEpisode 14 - Basics of HTML for Salesforce
Episode 14 - Basics of HTML for Salesforce
 
Html
HtmlHtml
Html
 
Css types internal, external and inline (1)
Css types internal, external and inline (1)Css types internal, external and inline (1)
Css types internal, external and inline (1)
 
CSS tutorial chapter 1
CSS tutorial chapter 1CSS tutorial chapter 1
CSS tutorial chapter 1
 
web development.pdf
web development.pdfweb development.pdf
web development.pdf
 

More from UC Berkeley Graduate School of Journalism (9)

Jquery plugins
Jquery pluginsJquery plugins
Jquery plugins
 
Inline, Block and Positioning in CSS
Inline, Block and Positioning in CSSInline, Block and Positioning in CSS
Inline, Block and Positioning in CSS
 
Jquery News Packages
Jquery News PackagesJquery News Packages
Jquery News Packages
 
HTML News Packages Lesson
HTML News Packages LessonHTML News Packages Lesson
HTML News Packages Lesson
 
Quiz
QuizQuiz
Quiz
 
Floats
FloatsFloats
Floats
 
CSS Tutorial
CSS TutorialCSS Tutorial
CSS Tutorial
 
Understanding DIVs
Understanding DIVsUnderstanding DIVs
Understanding DIVs
 
The 960 Grid System
The 960 Grid SystemThe 960 Grid System
The 960 Grid System
 

Recently uploaded

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 

Recently uploaded (20)

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 

CSS Fundamentals: External, Embedded & Inline Styles

  • 1. Cascading Style Sheets UC Berkeley Graduate School of Journalism Tuesday, March 15, 2011
  • 2. CSS fundamentals • CSS is for styling an HTML document. • CSS can affect fonts, sizes, colors, backgrounds, spacing, borders, and more. • CSS is its own language, with its own syntax. Tuesday, March 15, 2011
  • 3. Where is CSS kept? Tuesday, March 15, 2011
  • 4. One of three ways 1. Loaded in a separate document. 2. Specified in the <head> tag of the HTML document. 3. Specified directly in the HTML tags themselves. Tuesday, March 15, 2011
  • 5. One of three ways • External Style Sheets • Embedded Style Sheets • Inline Style Sheets Tuesday, March 15, 2011
  • 6. External Style Sheets <head  lang="en">    <meta  charset="utf-­‐8">    <title>This  is  my  title</title>    <meta  name="description"  content="This  is  an  example  of  my  webpage">    <meta  name="author"  content="Jeremy  Rue">    <link  rel="stylesheet"  href="css/style.css"> </head> Tuesday, March 15, 2011
  • 7. External Style Sheets • The best way to include CSS in a document. • The only drawback (and it’s a small one) is that if the style sheet is separate, therefore if it ever gets deleted then the page won’t look right. • Most general method of including styles. Tuesday, March 15, 2011
  • 8. Embedded Styles <head  lang="en"> <meta  charset="utf-­‐8"> <title>This  is  my  title</title>   <style  type="text/css"> h1  {color:red} p  {color:blue} </style> </head> Tuesday, March 15, 2011
  • 9. Embedded Styles • Will override any similar rules from external style sheets. • Sometimes this is used because you want a single page to have some different styles that the rest of your website. • Styles stay with the HTML page, because it’s a part of the page. Tuesday, March 15, 2011
  • 10. Inline Styles <body> <header> <h1  style=“color:red”>Hello  World</h1> </header> </body> Tuesday, March 15, 2011
  • 11. Inline Styles • The worst way to include CSS in a document. Avoid if possible. • Sometimes it can be needed, because you are working in a system where you just need one specific element, in a single webpage, to look a certain way and you don’t have access to the style sheets. Tuesday, March 15, 2011
  • 13. Parts of CSS element body  { font-­‐size:  12px; color:  #000000; } Tuesday, March 15, 2011
  • 14. Parts of CSS element body  { font-­‐size:  12px; color:  #000000; } This is the SELECTOR. It is specifying the part of the page that will be affected by the style. Tuesday, March 15, 2011
  • 15. Parts of CSS element body  { font-­‐size:  12px; color:  #000000; } These are PROPERTIES. There are a number of defined properties that you can change. Tuesday, March 15, 2011
  • 16. Parts of CSS element body  { font-­‐size:  12px; color:  #000000; } These are VALUES of the property. Tuesday, March 15, 2011
  • 17. Parts of CSS element body  { font-­‐size:  12px; color:  #000000; } A COLON separates the properties from the values. Tuesday, March 15, 2011
  • 18. Parts of CSS element body  { font-­‐size:  12px; color:  #000000; } A SEMI-COLON ends each line of code. Tuesday, March 15, 2011
  • 19. Parts of CSS element body  { font-­‐size:  12px; color:  #000000; } Note the CURLY BRACKETS, one opens and the other closes. Tuesday, March 15, 2011
  • 20. font-family • Specifies a family of fonts to use. Create a list of fallbacks should the user not have the font installed. • Put font names with more than one word in quotes. • Example: font-­‐family:“Times  New  Roman”,  Times,  serif Tuesday, March 15, 2011
  • 21. color • Specifies the color of text. • Specify one of three ways: Hexadecimal, RGB or simple names. We will use hexadecimal. • Example: color:#aaf999 Tuesday, March 15, 2011
  • 22. font-size • You should use either px or em. • PX stands for pixels, and is a fixed font size in Internet Explorer. • EM is a relative size, and is based on the default font size of the browser. • 1 em = 16 px in most browsers. • font pixels/16 = the size you want. Tuesday, March 15, 2011
  • 23. EXAMPLE body  { font-­‐family:“Palatino  Linotype”,   “Book  Antiqua”,  Palatino,  serif; color:  #eeeeee; } Tuesday, March 15, 2011
  • 24. background-color • Specifies the background color of an element using the same color units as color. We use hexadecimal. • Example: background-­‐color:  #f5f5f5; Tuesday, March 15, 2011
  • 25. Base Styles • Base styles means when you apply a style to an element, like h1, h2 or p. • Applies to that element throughout the document. • Example: h1  {      font-­‐family:  Helvetica,  Arial,  sans-­‐serif; } Tuesday, March 15, 2011
  • 26. Grouping (selectors) • If you want to apply a style to multiple elements, use a comma. • Example: h1,  h2,  h3  {      font-­‐family:  Helvetica,  Arial,  sans-­‐serif; } Tuesday, March 15, 2011
  • 27. Nested (Selectors) • If several base elements are listed with a space, it means only elements that are descendants of the first element. • Example: article  h1{            font-­‐size:  1.2  em; } Tuesday, March 15, 2011
  • 28. IDs vs Classes Tuesday, March 15, 2011
  • 29. IDs and Classes • IDs allow you specify specific elements in an HTML document. Each ID can only be specified once. • Classes allow you to specify a group of elements in an HTML document.You can use a class an unlimited number of times. Tuesday, March 15, 2011
  • 30. IDs • Each unique ID can be applied only once to a document. • HTML attribute example:  id=“copyright”   • CSS example: #copyright  {      font-­‐style:italic; } Tuesday, March 15, 2011
  • 31. Classes • Classes can apply to any number of elements. Use classes to group elements to your own grouping method. • HTML example: class=“headlines” • CSS  example: .headlines  {          font-­‐size:  1.2em; } Tuesday, March 15, 2011
  • 32. Selectors • There are lots of ways to specify the elements you are trying to style. • The most common: 1) base style 2) descendants 3) IDs/classes h2  {  color:#000000;  } h2  p  {  color:#000000;  } #firstpost  {  color:#000000;} Tuesday, March 15, 2011
  • 33. CSS Box Model Tuesday, March 15, 2011
  • 34. The Box Model <div  id=“content”> <p>Some  content  inside  the  box</p> </div> Tuesday, March 15, 2011
  • 36. The Box Model • Margin - Clears an area around the border. The margin does not have a background color, it is completely transparent • Border - A border that goes around the padding and content. • Padding - Clears an area around the content. • Content - The content of the box, where text and images appear Tuesday, March 15, 2011
  • 37. The Box Model • A DIV’s default height is defined by it’s content. • A DIV’s default width is defined by it’s parent’s width. • When width and height are defined, the content will “overflow” if it’s larger than the size of the box. Tuesday, March 15, 2011
  • 38. The Box Model #content  { border:  10px  solid  #98bf21; margin:  15px; padding:  10px; width:  300px; height:  300px; } Tuesday, March 15, 2011
  • 40. Box Model The width and height properties only define the size of the content area. Tuesday, March 15, 2011
  • 41. Assignment: Cookie Recipe 1. Find a cookie recipe online. Anything will do. 2. Include a photo, ingredients and directions and headline. 3. Make sure you style the: i. Fonts ii. Colors iii. And group it all in a box Tuesday, March 15, 2011