html5-img
1 / 26

Cascading Style Sheet

Cascading Style Sheet. Intoduction. Cascading Style Sheets, fondly referred to as CSS, is a simple design language intended to simplify the process of making web pages presentable.

ceana
Download Presentation

Cascading Style Sheet

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Cascading Style Sheet

  2. Intoduction • Cascading Style Sheets, fondly referred to as CSS, is a simple design language intended to simplify the process of making web pages presentable. • CSS handles the look and feel part of a web page. Using CSS, you can control the color of the text, the style of fonts, the spacing between paragraphs, how columns are sized and laid out, what background images or colors are used, as well as a variety of other effects. • CSS is easy to learn and understand but it provides powerful control over the presentation of an HTML document

  3. Advantages of CSS: • CSS saves time - You can write CSS once and then reuse same sheet in multiple HTML pages. You can define a style for each HTML element and apply it to as many Web pages as you want. • Pages load faster - If you are using CSS, you do not need to write HTML tag attributes every time. Just write one CSS rule of a tag and apply to all the occurrences of that tag. So less code means faster download times. • Easy maintenance - To make a global change, simply change the style, and all elements in all the web pages will be updated automatically. • Superior styles to HTML - CSS has a much wider array of attributes than HTML so you can give far better look to your HTML page in comparison of HTML attributes. • Multiple Device Compatibility - Style sheets allow content to be optimized for more than one type of device. By using the same HTML document, different versions of a website can be presented for handheld devices such as PDAs and cell phones or for printing. • Global web standards - Now HTML attributes are being deprecated and it is being recommended to use CSS. So its a good idea to start using CSS in all the HTML pages to make them compatible to future browser

  4. Parts of CSS CSS instruction or rules has two parts. • Selector • Declarations

  5. Selector HTML elements are known as selectors in CSS. Selector tells a browser which elements in a page are governed by the particular rule. It is the link between the HTML document and the style, and all HTML tags are possible selectors. These are two kinds of selectors: • Type • Attribute (class or id)

  6. Declarations The deceleration has two parts: • Property and • Value

  7. Associating CSS with HTML • Embedded Style Sheet • External Style Sheet • Inline Style Sheet • Using Classes

  8. Using Embedded Style Sheet Embedded style sheet are placed within the HTML document by defining it between the opening and closing <head> tag and <body> tag. To embed a style sheet you need to use the opening and closing <style> tags. <head> <title>------------------</title> <Style> </style> </head>

  9. Using Embedded Style Sheet Syntax Tag name { Style sheet Property : value} For example BODY{ Color: Blue} Embedded style sheet are most effective when you have a single HTML document to format.

  10. Using Embedded Style Sheet • Advantages • Can control style for a document in one place. • No additional download time for style information. • Disadvantages • Need to reapply style information for other document.

  11. Using External Style Sheet Suppose you are working with multiple documents and they share similar formatting. In this case, if you use embedded style sheets in each of the document, when in order to update the documents you need to adjust each and every style sheet. The best way is to have a separate style sheet file, which includes all the style definitions and associate it with the HTML document. The separate style sheet file must have the CSS extension. In this file the style definitions are placed within the opening and closing <STYLE> TAGS. The same syntax is used as in embedded style sheets.

  12. Using External Style Sheet • To associate the separate CSS file with the HTML file, you have two options: • Importing • Linking

  13. Importing In importing you need to add @ import URL (“…”); within the style block of the HTML document. The URL gives the address of the style sheet file. You can import any number of style sheet by including as many import statements. This method is useful if you are using multiple style sheet page that each has a particular function. Instead of having a large style sheet page you can work with multiple smaller ones.

  14. Linking • This method gives visitors a choice of style sheet to use for a specific page. You need to use a single <Link> tag within the opening and closing <head> tags. Syntax <LINK rel=stylesheethref=“CSS1.CSS” type=“text/CSS”>

  15. Using External Style Sheet Advantages • It can set style for many document with one style sheet. Disadvantages • Requires extra download time for style sheet, which may delay page rendering

  16. Using Inline Style Sheet Applying inline style definitions throughout an HTML document is similar to adding formatting extensions. For example <P style=“color:red;font-size:5px”>

  17. Using Inline Style Sheet Advantages • It can control style to a single character instance • Overrides any external or document styles Disadvantages • Need to reapply style information throughout the document and outside documents. • Bound too closely to HTML-difficult to update

  18. Selector • Definition: identifies the HTML elements that the rule will be applied to, identified by the actual element name, e.g. <body>, or by other means such as class attribute values. • Example

  19. Property & Value • Definition: The property is the style attribute you want to change. Each property has a value

  20. Declaration • Definition: Each CSS line that includes property and value

  21. Declaration Block • Definition: multiple declaration lines including the curly braces

  22. Curly Braces • Definition: the curly braces contain the properties of the element you want to manipulate, and the values that you want to change them to. The curly braces plus their content is called a declaration block.

  23. Let’s Create Our First CSS Page <html> <head> <style type="text/css"> p {color:red; text-align:center;} </style> </head> <body> <p>Hello World!</p> <p>This paragraph is styled with CSS.</p> </body> </html>

  24. Class and id Selectors • In addition to setting a style for a HTML element, CSS allows you to specify your own selectors called "id" and "class". id - The id selector is used to specify a style for a single, unique element. • The id selector uses the id attribute of the HTML element, and is defined with a "#". • The style rule below will be applied to the element with id="para1": • #para1 {text-align:center;color:red;}

  25. Let’s Create A CSS Page that uses “id” <html> <head> <style type="text/css"> #para1 { text-align:center; color:red; } </style> </head> <body> <p id="para1">Hello World!</p> <p>This paragraph is not affected by the style.</p> </body> </html>

  26. Let’s Create A CSS Page that uses “class” <html> <head> <style type="text/css"> .center { text-align:center; } </style> </head> <body> <h1 class="center">Center-aligned heading</h1> <p class="center">Center-aligned paragraph.</p> </body> </html>

More Related