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 Intro to CSS (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

social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 

Recently uploaded (20)

social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 

Intro to CSS

  • 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