• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
4.2 css classes
 

4.2 css classes

on

  • 658 views

 

Statistics

Views

Total Views
658
Views on SlideShare
264
Embed Views
394

Actions

Likes
0
Downloads
0
Comments
0

2 Embeds 394

http://coachandersonscomputer.blogspot.com 207
http://www.coachandersonscomputer.blogspot.com 187

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    4.2 css classes 4.2 css classes Presentation Transcript

    • CSS Classes
    • What is a CSS Class?
      • A CSS class provides us with a tool to create custom styles for elements on our web pages. Using classes can save us from typing the same formatting code for numerous elements. Classes enable us to make wide-scale styling changes very quickly.
      • In our earlier examples of using CSS, we applied the same formatting to all instances of a particular element. A CSS class allows us to define different styles for the same element type . For example, we can make one paragraph appear in green text and another paragraph show in red text.
    • Syntax and Use of CSS Classes: Class definitions are placed along with all the other CSS inside the <head> section of the document. <head> <style type=&quot;text/css&quot;> .center { text-align:center; } </style> </head> <p>Paragraph 1</p> <p class=&quot;center&quot; >Paragraph 2</p> A CSS class is defined with a period, followed by the name of the class. Paragraph 1 Paragraph 2 By adding the class=&quot;center&quot; to this paragraph element, we are telling the browser to apply all formatting defined for that class to this particular paragraph.
    • Syntax and Use of CSS Classes: As before, multiple styles can be defined in a single statement. Remember the semicolon at the end of each line. <head> <style type=&quot;text/css&quot;> .special { text-align:center; color:green; font-style:italic; } </style> </head> <p class=&quot;special&quot; >Paragraph</p> Paragraph
    • Syntax and Use of CSS Classes: CSS classes can even be combined. The element will reflect the formatting definitions from all the classes being applied. <head> <style type=&quot;text/css&quot;> .center { text-align:center; } .green { color:green; } .italic { font-style:italic; } </style> </head> <p class=&quot;center green italic&quot; >Paragraph</p> Paragraph
    • Syntax and Use of CSS Classes: Generic classes like these can be applied to any element we choose. <head> <style type=&quot;text/css&quot;> .green { color:green; } </style> </head> <h1 class=&quot;green&quot; >Heading</h1> <p class=&quot;green&quot; >Paragraph</p> <ul> <li>List Item 1</li> <li class=&quot;green&quot; >List Item 2</li> </ul>
      • Heading
      • Paragraph
      • List Item 1
      • List Item 2
    • Syntax and Use of CSS Classes: You can also specify that only particular elements be affected by a class. <head> <style type=&quot;text/css&quot;> p.green { color:green; } </style> </head> <h1 class=&quot;green&quot; >Heading</h1> <p class=&quot;green&quot; >Paragraph</p> <ul> <li>List Item 1</li> <li class=&quot;green&quot; >List Item 2</li> </ul>
      • Heading
      • Paragraph
      • List Item 1
      • List Item 2
      In this example, we have defined the .green class to apply only to the paragraph element. If we try to apply the .green class to other elements, it will have no effect; the browser will simply ignore the class definition.
    • The <span> element: The <span> tag allows us to apply class styling to a specific section within an element. <head> <style type=&quot;text/css&quot;> .green { color:green; } </style> </head> <p>This is a <span class=&quot;green&quot;> typical </span> paragraph</p> This is a typical paragraph. Note that the <span> tag does nothing on its own. Only when we associate it with a class does it make a change to how the page displays.
    • Naming CSS Classes:
      • Give some thought to how you name your CSS classes. By using class names that describe how the element will look (.green, .center), we can make things confusing in the future. What if we later change our green text to be red? We would have the .green class display in red!
      • A much better approach is to use class names that describe the meaning of the content, not how it will look:
      • Problematic names
        • .green
        • .underline
        • .center
        • .bigletters
      • Better names
        • .slogan
        • .booktitle
        • .caption
        • .headline