basic css lecture 15 - hampden-sydney...

22
Basic CSS Lecture 15 Robb T. Koether Hampden-Sydney College Mon, Feb 20, 2012 Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 1 / 22

Upload: others

Post on 26-Jun-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

Basic CSSLecture 15

Robb T. Koether

Hampden-Sydney College

Mon, Feb 20, 2012

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 1 / 22

Page 2: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

1 CSS

2 Background Styles

3 Text Styles

4 List Styles

5 Table Styles

6 The CSS Box Model

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 2 / 22

Page 3: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

Outline

1 CSS

2 Background Styles

3 Text Styles

4 List Styles

5 Table Styles

6 The CSS Box Model

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 3 / 22

Page 4: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

CSS

CSS = Cascading Style Sheet.A CSS file typically uses the .css extension.The CSS file determines how the HTML elements will appear.

SizeColorPositionBordersEtc.

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 4 / 22

Page 5: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

Internal Styles

Attributes<h1 align="center"><font color="red">My Home Page</font></h1>

Or

Styles<h1 style="text-align:center; color:red">My Home Page</h1>

The various element attributes can instead be grouped in a singlestyle attribute.

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 5 / 22

Page 6: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

CSS Colors

There is a long list of predefined color names.See http://www.w3schools.com/css/css_colornames.asp

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 6 / 22

Page 7: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

The Style Section

Attributes<head}><style>

h1 {text-align:center; color:red}h2 {text-align:center; color:blue}h3 {text-align:left; color:green}

</style></head>

The technique of the last example is of limited value.The strength of styles is that we can define the attributes of, say,the <h1>, <h2>, and <h3> heading tags once in a <style>element.These styles will be applied to all <h1>, <h2>, and <h3>headings.

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 7 / 22

Page 8: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

External Styles

The CSS file mystyle.cssh1 {text-align:center; color:red}h2 {text-align:center; color:blue}h3 {text-align:left; color:green}

The Link to the CSS File<link rel="stylesheet" type="text/css" href="mystyle.css" />

To facilitate maintaining a single style over multiple pages, thestyle section may be placed in a separate CSS file and thenincluded in each HTML file.Place a link to it in the <head> section of the HTML file.

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 8 / 22

Page 9: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

Outline

1 CSS

2 Background Styles

3 Text Styles

4 List Styles

5 Table Styles

6 The CSS Box Model

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 9 / 22

Page 10: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

Background Styles

We may set the background of the web page with the backgroundstyles.This style can be associated with any element for which it makessense.For example,

body - The entire document.p - Paragraphs only.h1 - h3 headings only.

We can set the backgroundColorImageTiling styleEtc.

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 10 / 22

Page 11: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

Background Styles

The CSS file mystyle.cssbody{

background-color: rgba(255, 0, 0, 0.2);background-image: url("Mt. Blanc.jpg");background-repeat: no-repeat;background-attachment: scroll;

}

For example, the above willSet the background color to light pink.Place the image “Mt. Blanc.jpg” over it.Attach the image to the upper-left corner.Scroll the image as the page is scrolled.

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 11 / 22

Page 12: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

A Shortcut

The CSS file mystyle.cssbody{

background: #ffdddd url("Mt. Blanc.jpg") repeat fixed;}

If we list the styles in this order:ColorImageRepeatAttachmentPosition

then we can use the above short-hand notation:

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 12 / 22

Page 13: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

Outline

1 CSS

2 Background Styles

3 Text Styles

4 List Styles

5 Table Styles

6 The CSS Box Model

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 13 / 22

Page 14: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

Text Styles

Text Stylesp{

color: blue;text-align: left;text-decoration: underline;text-indent: 50px;text-transform: capitalize;font-size: 30px;font-style: italic;font-family: Verdana;

}

We may style the text that occurs in headings, paragraphs, etc.

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 14 / 22

Page 15: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

Outline

1 CSS

2 Background Styles

3 Text Styles

4 List Styles

5 Table Styles

6 The CSS Box Model

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 15 / 22

Page 16: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

List Styles

List Stylesul{

list-style-image: url("red_dot.jpg");}

li{

background-color: lightpink;font-family: Verdana;font-size: 40px;padding-left: 30px;

}

We may set the style for lists.

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 16 / 22

Page 17: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

Outline

1 CSS

2 Background Styles

3 Text Styles

4 List Styles

5 Table Styles

6 The CSS Box Model

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 17 / 22

Page 18: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

Table Styles

Table Stylestable {background-color: green;}

th{

height: 50px;font-size: 30px;

}

td{

vertical-align: center;color: lightpink;

}

We may set a table <table>, a table header <th>, a table row<tr>, or table data <td>.

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 18 / 22

Page 19: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

Outline

1 CSS

2 Background Styles

3 Text Styles

4 List Styles

5 Table Styles

6 The CSS Box Model

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 19 / 22

Page 20: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

The CSS Box Model

Every HTML element is considered to lie within a box.The CSS box model consists of

The content areaPadding around the content areaA border around the paddingA margin around the border

We may set the size, color, and style of any of these, on the left,right, top, or bottom.We may set the height and width of the content area.

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 20 / 22

Page 21: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

The CSS Box Model

Hellowidth

heig

htcontent

padding

marginborder

The CSS Box ModelRobb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 21 / 22

Page 22: Basic CSS Lecture 15 - Hampden-Sydney Collegepeople.hsc.edu/faculty-staff/robbk/Coms480/Lectures... · 1 CSS 2 Background Styles 3 Text Styles 4 List Styles 5 Table Styles 6 The CSS

Table Styles

CSS Boxesp{

height: 150px;width: 25%;padding: 10px;border: 3px dotted green;margin: 50px;

}

Robb T. Koether (Hampden-Sydney College) Basic CSSLecture 15 Mon, Feb 20, 2012 22 / 22