Lecture 5 Css
Lecture 5 Css
web design
Lecture 4
Objectives
What is CSS?
Types of CSS
Inline
Embedded
External
3 What is CSS (Cascading Style Sheets)?
A style sheet is made up of one or more style instructions (called rules) that describe how
an element or group of elements should be displayed.
Style sheets are composed of "Rules" that describe the styling to be applied.
Inline Styles
Embedded/Internal Styles
External Styles
Three CSS Definition Locations
Inline: the “style” attribute
<p style=“font-color:red;font-size:10px;”>Content</p>
Note, the selector for inline CSS is the tag which contains the style attribute.
<html><head><style>
p{ background-color: Red;
font-family: serif;
font-color: White; }
</style></head>
<body>
<p>Content</p>
</body></html>
Inline CSS
Configured in the body of the web page
Use the style attribute of an HTML tag
Apply only to the specific element
<html>
<head> <title>Inline Style Sheets</title></head>
<body> <ol style="list-style-type:upper-alpha">
<li>one thing</li><li> or another</li>
<ul style="list-style-type:square; whitespace:pre">
<li> with this</li>
<li> or that</li>
</ul>
</ol>
</body>
</html>
Inline Style Sheets (cont.)
Styles
can be applied
<html>
<head> to
<table> ele-
<title> Inline Style Sheets </title> ments
</head>
<body> (and
sub-elements)
<table style="font-family: Arial,sans-serif">
<caption style="color: red; for
font-style: italic; interesting
text-decoration: underline">
Student data. </caption> effects.
<tr style="background-color: red"> This is better
<th> name </th> <th> age </th> handled using
</tr>
<tr> document or
<td> external style
Chris Smith </td>
<td> 19 </td> sheets.
</tr>
<tr>
<td> Pat Jones </td> <td> 20 </td>
</tr>
<tr><td>Doogie
Howser</td><td>9</td></tr>
</table>
Embedded Style Sheets
<style>
body { background-color: #000000;
color: #FFFFFF;
}
</style>
CSS Embedded Styles
19
<style>
body { background-color: #E6E6FA;
color: #191970;}
h1 { background-color: #191970;
color: #E6E6FA;}
h2 { background-color: #AEAED4;
color: #191970;}
Embedded Style Sheets
<html>
<head>
<title>Document Style Sheets</title>
<style>
h1 { color: blue; text-align:
center; }
p.indented { text-indent: 0.2in;
}
</style>
</head>
<body>
<h1> Centered Title </h1>
This second example would apply the “alert” to only the first
item in the list.
<ol>
<li class="alert">Help!</li>
<li>Beware!</li>
</ol>
Formatting
<html>
Tables Using CSS
<head>
<title> Inline Style Sheets </title>
<style type="text/css">
table { font-family: Arial,sans-serif; }
caption { color: red; font-style: italic;
text-decoration: underline; }
th { background-color:red; }
td { padding: 0 1em 0 2em; }
</style>
</head>
<body>
<table>
<caption> Student data.
</caption>
<tr><th> name </th> <th> age</th></tr>
<tr><td> Chris Smith </td> <td> 19 </td></tr>
<tr><td> Pat Jones </td> <td> 20 </td></tr>
<tr><td> Doug MacKenzie </td> <td> 32 </td></tr>
</table>
</body>
</html>
Exercise
Using CSS types learned so far, develop one page about your hobby.
This is page should include general information about your hobby.
After learning external style sheets, you will create one more page about your specialized hobby
type.
External Style Sheets
Modularity is key to the development and reuse of software.
External style sheets place the style definitions in a separate file (or
files).
Multiple pages can link to the same style sheet. This gives a consistent
look across the multiple pages of a website.
Possible to make a single change in a style sheet and it propagates
automatically to all pages that use that style sheet.
External style sheets represent the ultimate in separation of content and
its representation.
Modularity and Style Sheets
<html>
<head>
<title>Title for Page</title>
<link rel="stylesheet"
type="text/css"
href="myStyle.css"
title="myStyle">
</head>
<body>
<h1>Centered Title</h1>
<p class="indented">This
paragraph will have
the first
Here is a second line in the first
line indented, but
paragraph.</p>
subsequent lines
<p>This paragraph will not be indented. </p>
will be flush. <br>
<h1>The End</h1>
</body>
</html>
/* myStyle.css */
All webpages for a particular website will then link to that same
style sheet, in order to maintain a consistent look through the
set of webpages.
Note that no <style> tags are used in the external style sheet
file.
Modularity and Style Sheets
(cont.)
It is possible to use several style sheets, and it is quite common
to use one that specifies styles for a web browser and another
for styles to use when a webpage is printed.
For example, you could include two links in the <head> element
of the form
The <div> tag is similar to the <span> tag, useful for defining a
section of content to which you may apply style definitions
(using a class, id, or inline style declaration attribute with the
<div> tag).
....
ul { list-style-type: square; }
}
</style>
...
Bootstr
Bootstrap is a free and open-source framework and collection
ap of tools that can be used for creating websites.
Bootstr
Bootstrap is a free and open-source framework and collection
ap of tools that can be used for creating websites.
Bootstrap has design templates using HTML and CSS
declarations for forms, navigation elements, buttons,
typography, and other interface elements. It also includes
optional JavaScipt extensions (utilizing jQuery).
Bootstr
Bootstrap is a free and open-source framework and collection
ap of tools that can be used for creating websites.
Bootstrap has design templates using HTML and CSS
declarations for forms, navigation elements, buttons,
typography, and other interface elements. It also includes
optional JavaScipt extensions (utilizing jQuery).
Bootstrap has been designed to work with all major browsers
(but the alpha release, in August 2015, of Bootstrap 4 has
dropped support for Internet Explorer version 8). And it has
also been designed to support mobile devices through the use
of media queries in all of its CSS templates.
Bootstr
Bootstrap is a free and open-source framework and collection
ap of tools that can be used for creating websites.
Bootstrap has design templates using HTML and CSS
declarations for forms, navigation elements, buttons,
typography, and other interface elements. It also includes
optional JavaScipt extensions (utilizing jQuery).
Bootstrap has been designed to work with all major browsers
(but the alpha release, in August 2015, of Bootstrap 4 has
dropped support for Internet Explorer version 8). And it has
also been designed to support mobile devices through the use
of media queries in all of its CSS templates.
I won’t be covering Bootstrap here in this module, but want to
make you aware of its existence. You are free to utilize it in
making your own websites for this course (properly attributed,
of course), but I would strongly recommend you to familiarize
yourself with basic CSS concepts first.
Web Rules of Thumb (Ok, my rules of
thumb. . . )
HTML and CSS provide lots of neat features, but just because you
can add a feature doesn’t mean you should!
Web Rules of Thumb (Ok, my rules of thumb. . . )
HTML and CSS provide lots of neat features, but just because
you can add a feature doesn’t mean you should!
Don’t add features that distract from the content of the page.
Web Rules of Thumb (Ok, my rules of thumb. . . )
HTML and CSS provide lots of neat features, but just because
you can add a feature doesn’t mean you should!
Don’t add features that distract from the content of the page.
Some suggestions that I offer:
Web Rules of Thumb (Ok, my rules of
HTML and CSS provide lots of neat features, but just because
thumb.
you can. add
. ) a feature doesn’t mean you should!
Don’t add features that distract from the content of the page.
Some suggestions that I offer:
I Use (non-default) colors and fonts sparingly, and be
careful how elements fit together.
E.g. no purple text on a pink background, no “weird” fonts.
E.g. I find bright white text on a black background difficult
to read.
Web Rules of Thumb (Ok, my rules of
HTML and CSS provide lots of neat features, but just because
thumb.
you can. add
. ) a feature doesn’t mean you should!
Don’t add features that distract from the content of the page.
Some suggestions that I offer:
I Use (non-default) colors and fonts sparingly, and be
careful how elements fit together.
E.g. no purple text on a pink background, no “weird” fonts.
E.g. I find bright white text on a black background difficult
to read.
Consider the needs of visually impaired users of your
website!! (For example, use "em"s or percentages to
specify font sizes, not fixed pixel sizes.)
Web Rules of Thumb (Ok, my rules of
HTML and CSS provide lots of neat features, but just because
thumb.
you can. add
. ) a feature doesn’t mean you should!
Don’t add features that distract from the content of the page.
Some suggestions that I offer:
I Use (non-default) colors and fonts sparingly, and be
careful how elements fit together.
E.g. no purple text on a pink background, no “weird” fonts.
E.g. I find bright white text on a black background difficult
to read.
Consider the needs of visually impaired users of your
website!! (For example, use "em"s or percentages to
specify font sizes, not fixed pixel sizes.)
Remember that an estimated 8-10% of people have some
type of color-blindness, so choose color combinations
appropriately.
Web Rules of Thumb (Ok, my rules of
HTML and CSS provide lots of neat features, but just because
thumb.
you can. add
. ) a feature doesn’t mean you should!
Don’t add features that distract from the content of the page.
Some suggestions that I offer:
I Use (non-default) colors and fonts sparingly, and be
careful how elements fit together.
E.g. no purple text on a pink background, no “weird” fonts.
E.g. I find bright white text on a black background difficult
to read.
Consider the needs of visually impaired users of your
website!! (For example, use "em"s or percentages to
specify font sizes, not fixed pixel sizes.)
Remember that an estimated 8-10% of people have some
type of color-blindness, so choose color combinations
appropriately.
Some people use screen readers to read content on
webpages (so, e.g., include "alt" properties on images).
I Use images only where appropriate.
E.g. bright background images can make text hard to read.
E.g. using clickable images instead of standard HTML
buttons or links can slow access as images have to be
loaded.
I Use images only where appropriate.
E.g. bright background images can make text hard to read.
E.g. using clickable images instead of standard HTML
buttons or links can slow access as images have to be
loaded.
I Don’t rely on window or font size for layout.
E.g. the font size may be adjusted by the client.
Consider using CSS media queries to help account for
different devices people use.
I Use images only where appropriate.
E.g. bright background images can make text hard to read.
E.g. using clickable images instead of standard HTML
buttons or links can slow access as images have to be
loaded.
I Don’t rely on window or font size for layout.
E.g. the font size may be adjusted by the client.
Consider using CSS media queries to help account for
different devices people use.
I Don’t be annoying!
E.g. avoid lots of pop-up windows, silly music, etc.
I Use images only where appropriate.
E.g. bright background images can make text hard to read.
E.g. using clickable images instead of standard HTML
buttons or links can slow access as images have to be
loaded.
I Don’t rely on window or font size for layout.
E.g. the font size may be adjusted by the client.
Consider using CSS media queries to help account for
different devices people use.
I Don’t be annoying!
E.g. avoid lots of pop-up windows, silly music, etc.
I Break a large document (webpage) into several
smaller ones or provide a menu for navigation.
I Use images only where appropriate.
E.g. bright background images can make text hard to read.
E.g. using clickable images instead of standard HTML
buttons or links can slow access as images have to be
loaded.
I Don’t rely on window or font size for layout.
E.g. the font size may be adjusted by the client.
Consider using CSS media queries to help account for
different devices people use.
I Don’t be annoying!
E.g. avoid lots of pop-up windows, silly music, etc.
I Break a large document (webpage) into several
smaller ones or provide a menu for navigation.
I Utilize style sheets to make changes easy and
ensure consistency across a set of webpages.
Consider using a tool such as Bootstrap to assist with
different cross-browser CSS implementations.
I Use images only where appropriate.
E.g. bright background images can make text hard to read.
E.g. using clickable images instead of standard HTML
buttons or links can slow access as images have to be
loaded.
I Don’t rely on window or font size for layout.
E.g. the font size may be adjusted by the client.
Consider using CSS media queries to help account for
different devices people use.
I Don’t be annoying!
E.g. avoid lots of pop-up windows, silly music, etc.
I Break a large document (webpage) into several
smaller ones or provide a menu for navigation.
I Utilize style sheets to make changes easy and
ensure consistency across a set of webpages.
Consider using a tool such as Bootstrap to assist with
different cross-browser CSS implementations.
I Stick to standard features and test many browsers
if possible (and versions of the same browser).
Configuring Color with Inline CSS
52
<style>
class Selector .new { color: #FF0000;
font-style: italic;
Apply a CSS }
</style>
rule to a certain "class" of
elements on a web page
Does not associate the
style to a specific HTML element
Configure with .classname
code CSS to create a class called “new” with red italic text.
Apply the class:
<p class=“new”>This is text is red and in italics</p>
External Style Sheets - 1
55
site.css
index.html
index.html
body {background-color:#E6E6FA;
color:#000000;
font-family:Arial, sans-serif; clients.html
clients.html
font-size:90%; }
h2 { color: #003366; }
.nav { font-size: 16px; about.html
about.html
font-weight: bold; }
Etc…
link Element
57
A self-contained tag
Placed in the header section
Purpose: associates the external
style sheet file with the web page.
Example:
<link rel="stylesheet" href="color.css">
Using an External Style Sheet
58
Add another page to your first page using external style sheets.