css basics - wit-hdip-comp-sci.github.io · advantage: • sometimes called presentational markup,...
TRANSCRIPT
CSS Basics
3
Markup, Style, Function
• Markup (XHTML, HTML)
• Structure
• Content
• Style (CSS)
• Style
• Presentation
• Appearance
• Function (Javascript)
• Actions
• Manipulations
4
Content, Presentation, Behavior
• Content comprises the information the author wishes to convey to his or her audience, and is embedded within HTML or XHTML markup that defines its structure and semantics.
• Most of the content on the Web today is text, but content can also be provided through images, animations, sound, video, and whatever else an author wants to publish
5
Content, Presentation, Behavior
• Presentation defines how the content will appear to a human being who accesses the document in one way or another
• The conventional way to view a web page is with a regular web browser, of course, but that’s only one of many possible access methods. For example, content can also be converted to synthetic speech for users who have impaired vision or reading difficulties
6
Content, Presentation, Behaviour
• Behaviour layer involves real-time user interaction with the document.
• This task is normally handled by JavaScript.
• The interaction can be anything from a trivial validation that ensures a required field is filled in before an order form can be submitted, to sophisticated web applications that work much like ordinary desktop programs.
7
Separation of Concerns• It’s possible to embed all three layers
within the same document
• <em> and <b> can be used to control the presentation of text, and <hr> will insert a visible rule element
We can modify or replace any of the layers without
having to change the others.
Keeping them separate gives us one valuable
advantage:
• Sometimes called Presentational Markup, these types of elements embed presentation-layer information within the content layer, they negate any advantage we may have gained by keeping the layers separate.
What is CSS?
CSS is a language for specifying how documents are
presented to users — how they are styled &
laid out
Cascading Style Sheets is the recommended way to control the
presentation layer in a web document.
The main advantage of CSS over presentational HTML markup is
that the styling can be kept entirely separate from the
content.
CSS also provides far better control over presentation than do presentational element types in
HTML.
Example
index.html style.css
Two rules
The first rule starts with an h1 selector, which means that it will apply its property values to the <h1> element. It contains three properties and their values:
1. The first one sets the text color to blue.
2. The second sets the background color to yellow.
3. The third one puts a border around the header that is 1 pixel wide, solid (not dotted, or dashed, etc.), and colored black.
The second rule starts with a p selector, which means that it will apply its property values to the <p> element. It contains one declaration, which sets the text color to red.
Rules Applied to HTML document
Browser Render
How CSS Does it Work?
1. The browser converts HTML and CSS into the DOM (Document Object Model). The DOM represents the document in the computer's memory. It combines the document's content with its style.
2. The browser displays the contents of the DOM.
17
<link> element
18
One Stylesheet - Multiple html pages
<head> <title>App Store</title> <link type="text/css" rel="stylesheet" href=“style.css" /> </head>
<head> <title>Movies</title> <link type="text/css" rel="stylesheet" href="style.css" /> </head>
<head> <title>Music</title> <link type="text/css" rel="stylesheet" href="style.css" /> </head>
Style.css
Index.html
movies.html
music.html
Rules
Selectors
Declarations
Properties
Values
20
CSS Rule
21
Selector and Declarations
22
Properties & Values
23
A CSS Rule
24
More Properties...
• You can add as many properties and values as you like in each CSS rule.
• To put a border around your paragraphs: