web foundations tuesday, october 1, 2013 lecture 4: html color codes, intro to css styles

12
Web Foundations TUESDAY, OCTOBER 1, 2013 LECTURE 4 : HTML COLOR CODES, INTRO TO CSS STYLES

Upload: norman-morton

Post on 29-Dec-2015

217 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Web Foundations TUESDAY, OCTOBER 1, 2013 LECTURE 4: HTML COLOR CODES, INTRO TO CSS STYLES

Web FoundationsTUESDAY, OCTOBER 1, 2013

LECTURE 4: HTML COLOR CODES, INTRO TO CSS STYLES

Page 2: Web Foundations TUESDAY, OCTOBER 1, 2013 LECTURE 4: HTML COLOR CODES, INTRO TO CSS STYLES

HTML Color Codes

http://www.w3schools.com/html/html_colors.asp

http://www.w3schools.com/html/html_colornames.asp

• Red/Green/Blue Hecadecimal Triplets• 0123456789abcdef

• Red/Green/Blue RGB Decimal Code• 0 - 255

• X11 Color Names• thistle, magenta, indigo, gray, grey

• HSL/HSV• 0 - 360° , 0 - 100%, 0 - 100%

• Web Safe Colors• VGA 256 216 (6 × 6 × 6 = 216)

each from 00 to FF

http://www.computerhope.com/htmcolor.htm

http://www.computerhope.com/color-qa.htm

http://html-color-codes.info/

/* RGB model */#F00 /* 3-digit shortchand hex form #rgb */#FF0000 /* 6-digit traditional hex form #rrggbb */rgb(255, 0, 0) /* integer range 0 - 255 */rgb(100%, 0%, 0%) /* float range 0.0% - 100.0% */ /* RGB with alpha channel, added to CSS3 */rgba(255, 0, 0, 0.5) /* 0.5 opacity, semi-transparent */ /* HSL model, added to CSS3 */hsl(0, 100%, 50%) /* red */hsl(120, 100%, 50%) /* green */hsl(120, 100%, 25%) /* dark green */hsl(120, 100%, 75%) /* light green */hsl(120, 50%, 50%) /* pastel green */ /* HSL model with alpha channel */hsla(120, 100%, 50%, 1) /* green */hsla(120, 100%, 50%, 0.5) /* semi-transparent green */hsla(120, 100%, 50%, 0.1) /* very transparent green */

http://en.wikipedia.org/wiki/Web_colors

Page 3: Web Foundations TUESDAY, OCTOBER 1, 2013 LECTURE 4: HTML COLOR CODES, INTRO TO CSS STYLES

What is CSS ?

• CSS stands for Cascading Style Sheets• Styles define how to display HTML elements• Styles were added to HTML 4.0 to solve a problem of separating content from

the way it is formatted and displayed• External Style Sheets can save a lot of work by adding formatting and display

configuration to an entire web site• External Style Sheets are stored in .css files

CSS is a way to style and present the information offered in an HTML page. Whereas the HTML is the meaning or content, the style sheet is the presentation of that document, including its font size and type, item colors, item formatting, margins and padding, rows and columns, in short the look and feel of a web page or entire web site.

Page 4: Web Foundations TUESDAY, OCTOBER 1, 2013 LECTURE 4: HTML COLOR CODES, INTRO TO CSS STYLES

Three Ways to Insert CSS into an HTML Page

• Inline Style• Internal Style Sheet• External Style Sheet

CSS Styling Lab and Styling with External Style Sheets [due Wednesday, October 9, by midnight]

Page 5: Web Foundations TUESDAY, OCTOBER 1, 2013 LECTURE 4: HTML COLOR CODES, INTRO TO CSS STYLES

Inline Style

Inline style does exactly what it sounds like, it adds a style or styles in direct line with the HTML code itself (i.e., it is "embedded" inline with the HTML code)

An inline style loses many of the advantages of style sheets by mixing content with presentation.

To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example below shows how to change the font color and the left and right margins of a paragraph:

<p style="color:sienna; margin-left:20px; margin-right:600px;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut pellentesque iaculis luctus. Phasellus quis faucibus turpis. Ut convallis quam id risus mattis lobortis. Cras quis augue vulputate, laoreet mauris id, pharetra ligula. Curabitur placerat sem eros, non rhoncus justo sollicitudin eu.</p>

Page 6: Web Foundations TUESDAY, OCTOBER 1, 2013 LECTURE 4: HTML COLOR CODES, INTRO TO CSS STYLES

Internal Style Sheet

An internal style sheet should be used when a single document has a unique style. You define internal styles in the head section of an HTML page, by using the <style> tag, like this:

<head><style>p {margin-left:20px; margin-right:600px; color:red;}body {background-color: #ffff99;} <!– or the pair shortcut #ff9 --></style></head>

Page 7: Web Foundations TUESDAY, OCTOBER 1, 2013 LECTURE 4: HTML COLOR CODES, INTRO TO CSS STYLES

CSS Syntax

A CSS declaration always ends with a semicolon, and declaration groups are surrounded by curly brackets or "squiggles":

p {color:red; text-align:center;}

NOTE: We will talk about creating and using "class" and "id" in CSS in a future lecture

Page 8: Web Foundations TUESDAY, OCTOBER 1, 2013 LECTURE 4: HTML COLOR CODES, INTRO TO CSS STYLES

External Style Sheet

An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can change the look of an entire Web site by changing one file. Each page must link to the style sheet using the <link> tag. The <link> tag goes inside the head section:

<head><link rel="stylesheet" type="text/css" href="style.css"> <!-- in HTML5 type="text/css" can be omitted--></head>

An external style sheet can be written in any text editor. The file should not contain any html tags. Your style sheet should be saved with a .css extension and given any name you choose appropriate to your design intentions (e.g., style.css). An example of a style sheet file is shown below:

p {color:red; margin-left:20px; margin-right:600px;}

body {background-color: #cccc66;}

style.css

index.html

FYI: link rel is link relation and in our case it is a "stylesheet". There are other types of relations besides stylesheet, like author, help, license, search, to name a few.

Page 9: Web Foundations TUESDAY, OCTOBER 1, 2013 LECTURE 4: HTML COLOR CODES, INTRO TO CSS STYLES

Style Sheet Element Formatting

p {color:red; margin-left:20px; margin-right:600px;}

body {background-color: #cccc66;}

The way you format your style sheet is really up to you. Pick a style that you like and then stick with it for consistency.

p {color:red; margin-left:20px; margin-right:600px;}

body {background-color: #cccc66;}

p { color:red; margin-left:20px; margin-right:600px;}

body { background-color: #cccc66;}

Page 10: Web Foundations TUESDAY, OCTOBER 1, 2013 LECTURE 4: HTML COLOR CODES, INTRO TO CSS STYLES

Multiple Style Sheets and TypesIf some properties have been set for the same selector in different style sheets, the values will be inherited from the more specific style sheet. For example, an external style sheet has these properties for the h3 selector:h3{ color:red;text-align:left;font-size:8pt;}

And an internal style sheet has these properties for the h3 selector:h3{text-align:right;font-size:20pt;}

If the page with the internal style sheet also links to the external style sheet the properties for h3 will be:color:red; from the external text-align:right; from the internalfont-size:20pt; from the internal

The color is inherited from the external style sheet and the text-alignment and the font-size is replaced by the internal style sheet.

Page 11: Web Foundations TUESDAY, OCTOBER 1, 2013 LECTURE 4: HTML COLOR CODES, INTRO TO CSS STYLES

Styles can be specified three ways:

• inside an HTML element• inside the head section of an HTML page• in an external CSS file

Tip: multiple external style sheets can be referenced inside a single HTML document.

Cascading Order

What style will be used when there is more than one style specified for an HTML element? 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 default2. External style sheet3. Internal style sheet (in the head section)4. Inline style (inside an HTML element)

So, an inline style (inside an HTML element) has the highest priority, which means that it will override a style defined inside the <head> tag, or in an external style sheet, or in a browser (a default value).

NOTE: If the link to the external style sheet is placed after the internal style sheet in HTML <head>, the external style sheet will override the internal style sheet!

Page 12: Web Foundations TUESDAY, OCTOBER 1, 2013 LECTURE 4: HTML COLOR CODES, INTRO TO CSS STYLES

Pros and Cons of the Three Different CSS Styles

Inline StylePros – Fast, down-and-dirty way to get styles into the code; great for testing or roughing out an idea; comes in handy in unique situationsCons – Can be tedious because it's on an item by item basis; if you want to change a style you have to work down through your code to find the style, and you've have to do this through your entire page, then you'd have to repeat this through all your other pages whose style you want to change in the same way

Internal StylePros – Almost as fast as inline styleCons – If you have multiple pages that use the same internal style, and you change one page, then you have to go through ALL your pages to manually change the CSS style to make sure all your pages are the same

External StylePros – It is common for websites to have common 'theme' across all its pages. You can club all such common styles in external file and with one download you get the required style that can be used in multiple pages: saves download time; if you want to change style throughout your entire site, you only have to do this in the external file, and not manually going through each one of your pages (saves a LOT of time if you have many pages in your site)Cons – There will be one additional HTTP request for each external style sheet you have