1 / 12

Web Foundations

Web Foundations. Tuesday, October 1, 2013 LECTURE 4 : HTML Color CODES, INTRO TO CSS Styles. HTML Color Codes. Red/Green/Blue Hecadecimal Triplets 0123456789abcdef Red/Green/Blue RGB Decimal Code 0 - 255 X11 Color Names thistle, magenta, indigo, gray, grey HSL/HSV

ami
Download Presentation

Web Foundations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Web Foundations Tuesday, October 1, 2013 LECTURE 4: HTML Color CODES, INTRO TO CSS Styles

  2. HTML Color Codes • 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 /* 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://html-color-codes.info/ http://www.w3schools.com/html/html_colors.asp http://www.w3schools.com/html/html_colornames.asp http://www.computerhope.com/htmcolor.htm http://www.computerhope.com/color-qa.htm http://en.wikipedia.org/wiki/Web_colors

  3. What is CSS ? • CSSstands 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 .cssfiles • CSS is a way to style and presentthe 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.

  4. 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]

  5. 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;">Loremipsum dolor sit amet, consecteturadipiscingelit. Utpellentesqueiaculisluctus. Phasellusquisfaucibusturpis. Utconvallis quam id risusmattislobortis. Crasquisauguevulputate, laoreetmauris id, pharetra ligula. Curabiturplaceratsemeros, non rhoncusjustosollicitudineu.</p>

  6. 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>

  7. 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

  8. 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 .cssextension 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: index.html style.css p{color:red; margin-left:20px; margin-right:600px; } body{background-color: #cccc66; } FYI: link relis 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.

  9. Style Sheet Element Formatting 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;} p { color:red; margin-left:20px; margin-right:600px; } body { background-color: #cccc66; }

  10. Multiple Style Sheets and Types If 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 externaltext-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.

  11. 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: • Browser default • External style sheet • Internal style sheet (in the head section) • 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!

  12. Pros and Cons of the Three Different CSS Styles Inline Style Pros– Fast, down-and-dirty way to get styles into the code; great for testing or roughing out an idea; comes in handy in unique situations Cons– 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 Style Pros– Almost as fast as inline style Cons– 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 Style Pros– 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

More Related