1 / 44

CSS

CSS. Cascading style sheet Essam Hamed Abbas 9/9/2014 11:10 AM. INTRODUCTION.

iago
Download Presentation

CSS

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. CSS Cascading style sheet Essam Hamed Abbas 9/9/2014 11:10 AM

  2. INTRODUCTION • Cascading Style Sheets (CSS) enable you to precisely control the formatting of elements on your Web pages. HTML was designed to control the structure of your Web pages, such as headings, images, links, paragraphs and tables. Style sheets were designed to control the formatting of these elements in far greater detail than the HTML commands allow. Styles are the rules that define how the elements appear in a Web page, such as font and color.

  3. Why use CSS • CSS give you more choices in formatting, such as line spacing, paragraph indentation, borders and content placement. Creating styles that are used repeatedly in a Web page take less typing than the equivalent formatting with <font> tags, thus saving you kilobytes of disk space – which means your Web pages display faster.

  4. Advantages of Style Sheets • Saves time • Easy to change • Keep consistency • Give you more control overpage layout • Use styles with JavaScript => HTML • Make it easy to create a common format for all the Web pages

  5. Applying a single style sheet to multiple documents

  6. Basic Structure of a Style • Each definition contains: • A property • A colon • A value • A semicolon to separate two or more values • Can include one or more values • h1 {font-size:12px;color:red}

  7. Style Precedence • External style sheet • Embedded styles • Inline styles

  8. Three Style Types • Inline styles • Add styles to each tag within the HTML file • Use it when you need to format just a single section in a web page • Example • <h1 style=color:red;font-size:200;font-family: Arial>text..</h1>

  9. Example 1

  10. Three Style Types • Embedded or internal styles • A style is applied to the entire HTML file • Use it when you need to modify all instances of particular element (e.g., h1) in a web page • Example • <style> • h1 {color:red; font-family:sans-serif,margin-top:100px} • </style>

  11. Creating an Embedded Style <head> <title>Embedded Example</title> <style> (default is “text/css”) Style declarations </style> </head> • A style declaration: • Selector {attribute1:value1; attribute2:value2; …} • Selector = an element in a document (e.g., a header or body,table….)

  12. An Example of an embedded style <head> <title>Getting Started</title> <style> h1 {font-family: sans-serif; color: organge} </style> </head>

  13. Example2

  14. Three Style Types • External style sheets • An external style sheet is a text file containing the style definition (declaration) • Use it when you need to control the style for an entire web site • Example • h1, h2, h3, h4, h5, h6 {color:red; font-family:Arial} • Save this in a new document using a .css extension

  15. Creating an External Style Sheet • Open a new blank document in Notepad • Type style declarations • h1 {color:red; font-family:sans-serif;} • Do not include <style> tags • Save the document as filename.css

  16. Linking to Style Sheets 1 • Open an HTML file • Between <head> and </head> add • <link href=URL rel=“relation_type” type=“link_type”> • URL is the file.css • Relation_type=“stylesheet” • Link_type=“text/css” • Save this file and the .css file in the same web server directory

  17. An example of an external style sheet with an original html file <head> <title>Getting Started</title> <link href=“scraps.css” rel=“stylesheet” type=“text/css” /> </head> h1 {font-family: sans-serif; color: orange} Text file of css named “stylesheet” html file

  18. Example 4

  19. Style Sheet Strategies • Wherever possible, place your styles in external style sheets • Take advantage of the power of CSS to have control over an entire Web site

  20. Style Sheet Strategies • At the top level of your web site: define a default global.css style sheet • Refine styles at sublevels with a section.css style sheet • Try to avoid using styles in tags

  21. Attribute Selectors • Create an attribute selector to select an element based on the element’s attributes.

  22. Using IDs and Classes • Use an id to distinguish something, like a paragraph, from the others in a document.

  23. Working With Ids • To create an ID for a specific tag, use the property: • <tag ID=id_name> • To apply a style to a specific ID, use: • #id_name {style attributes and values}

  24. Classes • HTML require each id be unique– therefore an id value can only be used once in a document. • You can mark a group of elements with a common identifier using the class attribute. <element class=“class”> … </element>

  25. Cont.... .darkgreen { background-color: #00573D;} .lightgreen { background-color: #C6D6CE;} <h1 class=”darkgreen”>First Heading</h1> <p class=”lightgreen”>The text in this paragraph has a light green background color.</p> <p>Here we have another paragraph, but only <span class=”lightgreen”>some text</span> has a light green background color.</p>

  26. Example 5

  27. Applying a style to a class

  28. Working With Classes and Ids • The difference between the Class property and the ID property is that the value of the ID property must be unique: • you can’t have more than one tag with the same ID value • You can apply the same Class value to multiple document tags

  29. Working With DIV • <DIV> tag is used for blocks of text, e.g., paragraphs, block quotes, headers, or lists • To create a container for block-level elements, use: • <DIV CLASS=class_name> • Block-level elements • </DIV> • Class_name is the name of the class • You can substitute the ID proper for the Class property (with ID, the syntax for CSS style, #id_name {style attributes and values}

  30. Example 6

  31. Working With <span> • With the <span> tag, you can use inline elements, e.g., <B>, <I> • To create a container for inline elements, use: • <span CLASS=class_name> • inline elements • </span>

  32. CSS for Page Layout • CSS manipulates the size and location of block-level elements • Block-level elements in HTML: • Heading tags, e.g., <H1>, <H2> • <p> • <blockquote> and <address> tags • List tags, e.g., <ul>, <ol>, <dl> • <div> • <body> • <hr> • <img>

  33. CSS for Page Layout • Parts of the block-level elements: • Margin • Border • Padding

  34. padding border margin CSS for Page Layout (Carey, 7.49) I appreciate the prompt delivery of the pack of star disks.

  35. Controlling the Margins • To define the margins of an element, use: • margin:value • where value = a length value (“em” is often used), a percentage (a margin proportional to the element’s width, or auto

  36. Controlling the Margins • To set margins on a side, use: • margin-top • margin-right • margin-bottom • margin-left • E.g., LI {margin-left:2em; margin-right:2em; margin-top:1em; margin-bottom:1em}

  37. Setting the Padding Size • To define padding, use: • padding: value • where value = a length value or a percentage (a padding proportional to the element’s width)

  38. Setting the Padding Size • To set margins on a side, use: • padding-top • padding-right • padding-bottom • padding-left

  39. Formatting the Border • Border can be set in three ways: • border-width • border-style • border-color

  40. Formatting the Border • To set the border, use: • border:width_value style color • To set borders on a side, use: • border-top • border-bottom • border-left • border-right • Carey 7.52-7.53

  41. Formatting Width & Height of Block-Level Boxes • To set the width of a block-level element, use: • width:value • height:value • where value can be a length value, a percentage, or auto • E.g., textarea {width:225px; height:100px}

  42. Using the Float Attribute (p. 371-372) • To float (wrap) a block-level element, use: • float:margin • Where margin = right, left, none • To prevent an element from wrapping, use: • Clear:margin • Where margin=right, left, both, none

  43. Using the Float Attribute float:right width:50px clear:right float:right width:50px

  44. Formatting Hypertext Links • To remove the style of underlining hypertext, use: • A {text-decoration:none} • 4 types of hyperlinks can be modified: • A:visited {styles for previously visited links} • A:link {styles for links that have never visited} • A:active {styles for links that are currently being clicked} • A:hover {styles when the mouse cursor is hovering over the link}

More Related