Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.



Published on

Cascading Style Sheeting in work

  • Be the first to comment


  1. 1. CSS (Cascading Style Sheets) Presented by Prof Venkat Krishnan
  2. 2. Topics to be Covered <ul><li>Linking a style to an HTML document </li></ul><ul><li>In line style </li></ul><ul><li>External style sheet </li></ul><ul><li>Internal style sheet </li></ul><ul><li>Multiple styles </li></ul><ul><li>Introduction to DHTML </li></ul>
  3. 3. What is CSS <ul><li>The goal of Cascading Style Sheets (CSS) is to separate a Web page’s style from its structure and to make it easier to maintain Web pages that you’ve created. </li></ul><ul><li>Style sheets give you precise control over how structural elements appear on a Web page. What’s even better is that you can create one style sheet for an entire Web site to ensure that the layout and look of your content is consistent from page to page. </li></ul><ul><li>Cascading Style Sheets (CSS) provide you with more flexibility and allow you to control alignment, color, line height, kerning, and so forth in ways that HTML never could </li></ul>
  4. 4. <ul><li>However, there is a slight catch. CSS support appeared in Web browsers in the late 1990s. </li></ul><ul><li>By now, most users have upgraded to browsers that support CSS fully. However, studies show that about 10 percent of users have not upgraded and may not upgrade soon. </li></ul><ul><li>That means that you must decide whether that 10 percent falls into your target audience. If so, plan accordingly. </li></ul>
  5. 5. What you can do with CSS <ul><li>You can control just about every aspect of a page’s display — from borders to font sizes and everything in between: </li></ul><ul><li>Background properties control the background colors associated with blocks of text and with images. You can also use these properties to attach background colors to your page or to individual elements. </li></ul><ul><li>Border properties control borders associated with the page, lists, tables, images, and block elements (such as paragraphs). You can specify border width, color, style, and distance from the element’s content. </li></ul><ul><li>Classification properties control how elements such as images flow on the page relative to other elements. You can use these properties to integrate images and tables with the text on your page. </li></ul><ul><li>List properties control how lists appear on your page, such as </li></ul><ul><li>• Managing list markers </li></ul><ul><li>• Using images in place of bullets </li></ul>
  6. 6. CSS Structure and Syntax <ul><li>A style sheet is made of style rules. Each style rule has two parts: </li></ul><ul><li>Selector: Specifies the markup element to which the style rules apply. </li></ul><ul><li>Declaration: Specifies how the content described by the markup looks. You use a set of punctuation marks and special characters to define a style rule. The syntax for a style rule always follows this pattern: </li></ul><ul><li>selector { declaration } </li></ul>
  7. 7. <ul><li>A declaration breaks down further into two items: </li></ul><ul><li>Properties are aspects of how the computer displays text and graphics (for example, font size or background color). </li></ul><ul><li>Values are the data that specify how you want text and images to look on your page (for example, a 24-point font size or a yellow background). You separate the property from the value in a declaration with a colon: </li></ul><ul><li>selector { property : value } </li></ul>
  8. 8. <ul><li>For example, these three style rules set the colors for first-, second-, and third-level headings: </li></ul><ul><li>h1 {color: teal} </li></ul><ul><li>h2 {color: maroon} </li></ul><ul><li>h3 {color: black} </li></ul><ul><li>Style sheets override a browser’s internal display rules; your formatting specifications affect the final appearance of the page in the user’s browser. This means you can better control how your content looks and create a more consistent and appropriate experience for visitors </li></ul>
  9. 9. <ul><li>You probably want a style rule to affect the display of more than one property for any given selector. You can create several style rules for a single selector, each with one declaration, like this: </li></ul><ul><li>h1 {color: teal} </li></ul><ul><li>h1 {font-family: Arial} </li></ul><ul><li>h1 {font-size: 36px} </li></ul><ul><li>However, such a large collection of style rules becomes hard to manage. CSS lets you combine several declarations in a single style rule that affects the display characteristics of a single selector, like this: </li></ul><ul><li>h1 {color: teal; </li></ul><ul><li>font-family: Arial; </li></ul><ul><li>font-size: 36px} </li></ul>
  10. 10. <ul><li>You can make the same set of declarations apply to a collection of selectors, too: You just separate the selectors with commas. The following style rule applies the declarations for text color, font family, and font size to the h1, h2,and h3 selectors: </li></ul><ul><li>h1, h2, h3 {color: teal; </li></ul><ul><li>font-family: Arial; </li></ul><ul><li>font-size: 36px} </li></ul><ul><li>If you want a style rule that applies only to paragraphs that hold copyright information, you need a way to tell the browser that the rule has a limited scope. </li></ul>
  11. 11. <ul><li>To target a style rule more closely, combine the class attribute with a markup element. The following examples show HTML for two kinds of paragraphs: </li></ul><ul><li>A regular paragraph (without a class attribute) </li></ul><ul><li><p>This is a regular paragraph.</p> </li></ul><ul><li>A class attribute with the value of copyright </li></ul><ul><li><p class=”copyright”>This is a paragraph of class copyright.</p> </li></ul><ul><li>To create a style rule that applies only to the copyright paragraph, follow the paragraph selector in the style rule with </li></ul><ul><li>A period (.) </li></ul><ul><li>The value of the class attribute, such as copyright </li></ul>
  12. 12. What style will be used when there is more than one style specified for an HTML element? <ul><li>Generally speaking we can say that all the styles will &quot;cascade&quot; into a new &quot;virtual&quot; style sheet by the following rules, where number four has the highest priority: </li></ul><ul><li>Browser default </li></ul><ul><li>External style sheet </li></ul><ul><li>Internal style sheet (inside the <head> tag) </li></ul><ul><li>Inline style (inside an HTML element) </li></ul><ul><li>So, an inline style (inside an HTML element) has the highest priority, which means that it will override a style declared inside the <head> tag, in an external style sheet, or in a browser (a default value). </li></ul>
  13. 13. CSS Comments <ul><li>Comments are used to explain your code, and may help you when you edit the source code at a later date. A comment will be ignored by browsers. A CSS comment begins with &quot;/*&quot;, and ends with &quot;*/&quot;, like this: </li></ul><ul><li>/* This is a comment */ </li></ul><ul><li>p{text-align: center; </li></ul><ul><li>/* This is another comment */ </li></ul><ul><li>color: black;font-family: arial} </li></ul>
  14. 14. How to Insert a Style Sheet <ul><li>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 one file. Each page must link to the style sheet using the <link> tag. The <link> tag goes inside the head section: </li></ul><ul><li><head> </li></ul><ul><li><link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;mystyle.css&quot; /> </li></ul><ul><li></head> </li></ul>
  15. 15. <ul><li>An internal style sheet should be used when a single document has a unique style. You define internal styles in the head section by using the <style> tag, like this: </li></ul><ul><li>BorderMargin.html </li></ul>
  16. 16. <ul><li>An inline style loses many of the advantages of style sheets by mixing content with presentation. Use this method sparingly, such as when a style is to be applied to a single occurrence of an element. </li></ul><ul><li>To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example shows how to change the color and the left margin of a paragraph </li></ul>
  17. 17. Inheriting styles <ul><li>The CSS specification recognizes that you often nest one element inside another and wants to be sure that styles associated with the parent element find their way to the child element. This mechanism is called inheritance. </li></ul><ul><li>Multiple style sheets can affect page elements and build upon one another. It’s like inheriting styles within a Web page. This is the cascading part of CSS. </li></ul><ul><li>Here’s a real-world example: a Web site for university’s English department. The English department is part of the School of Humanities, which is just one school in the overall university. Each of these entities — the university, the school, and the English department — has its own style sheet. </li></ul>
  18. 18. <ul><li>1. The university’s style sheet provides style rules for all of the pages in the overall site. </li></ul><ul><li>2. The school’s style sheet links to the university’s style sheet (using an @import statement), and adds more style rules specific to the look the school wants for its own site. </li></ul><ul><li>3. The English department’s style sheet links to the school’s style sheet. </li></ul><ul><li>So the department’s pages both have their own style rules and inherit the style rules from both the school and the university’s style sheet. </li></ul>
  19. 19. DHTML <ul><li>DHTML stands for D ynamic HTML . </li></ul><ul><li>DHTML is not a standard defined by the World Wide Web Consortium (W3C). DHTML is a &quot;marketing term&quot; - used by Netscape and Microsoft to describe the new technologies the 4.x generation browsers would support. </li></ul><ul><li>W3C once said: &quot;Dynamic HTML is a term used by some vendors to describe the combination of HTML, style sheets and scripts that allows documents to be animated.&quot; </li></ul>