VirtualMV/CSS/Inline, embedded, linked

From WikiEducator
< VirtualMV‎ | CSS
Jump to: navigation, search



Overview

Styles can be saved in an external file (called the cascading style sheet, or css) and can be attached to multiple pages. This allows one style sheet to be applied to multiple pages in your site. Changing the style definition in the css will change the HTML elements of any attached pages.


VmvIcon Objectives.png

By the end of this page you will be able to:

  • Describe inline, embedded and linked styles

Examples of how styles can be applied

Inline (directly in the tag)

 <p style="color: #00FF00">Paragraph one</p>

Inline (inside a <span> tag or <div> tag)

when only a part of a paragraph is to have a style applied

 <p>Hello <span style="color:red">world</span>, Michael here</p>

when lots of tags are to have the style applied use the <div> tag

 <div style="color:red">
 <p>This is red</p>
 <p>This is also red</p>
 </div>

Embedded: In a style sheet in the web page

(placed in the <head> area

 <style type="text/css">
  h1 {
    color: #FF0000;
  }
 </style>

Linked: In a style sheet (text document)linked to the web page

  • one.css contains:
 h2 {color: #0000FF;}
 .center {text-align: center}
  • this is linked in the head area of the web page
 <link rel="stylesheet" type="text/css" href="one.css" />
  • And all h2 tags in the web page will be blue (#0000FF), and you can use class="center" to any tag to center the contents, e.g.
<h1 class="center">This heading will be center-aligned</h1>
 <p class="center">This paragraph will 	also be center-aligned.</p>

Why cascading?

An important feature of a style sheet is it’s ability to cascade. That is any definitions will be applied successively.

So if a style for h1 occurs inline, embedded and linked. The linked will be applied first, then the embedded then the inline.

For example: if inline = blue, embedded = green and linked = red, h1 will display blue.

  • Generally speaking we can say that all the styles will "cascade" into a new "virtual" Style Sheet by the following rules, where number four has the highest priority:
  1. Browser default
  2. External Style Sheet
  3. Internal Style Sheet (inside the <head> tag)
  4. Inline Style (inside HTML element)

Products such as Expression Web, Dreamweaver, and Frontpage support the use of Style Sheets, and make it easy to work with the formatting options.

Resources

VmvIcon References.png References

  1. CSS Course Tutorials and Reference Guide Online (2011). Retrieved from http://www.developphp.com/list_css.php

virtualMV  |  Superquick wiki guide  |  Please give me some feedback

VirtualMV/CSS/Inline, embedded, linked. (2024). In WikiEducator/VirtualMV wiki. Retrieved March 29, 2024, from http:https://wikieducator.org/VirtualMV/CSS/Inline,_embedded,_linked    (zotero)