Chapter 2 Creating Style Sheets

Style aka rule

 

selector declaration_block

ul { color:red; font-size: 1.5em; }

Style Sheets can be:.

  1. inline using style attribute, e.g. previous <ul> block
  2. internal inside document using <style> tags
  3. external separate .css file that is loaded
    best pracitice use external style sheet
    goal is consistent look and feel for entire site

Nota Bene, when you alter a Web Page, the browser may use cached a previous version, you may need to reload the page type F5 (FireFox ctrl^R) or refresh icon usually w address bar

Just loaded internal style color #ff7643 rrggbb best to use xll css color names; font arial

I just set the color red for paragraph, we normally put the style block inside <head>

External Style sheet is external CSS file, use a consistent name like webcast2.css, styles.css, we also organize into a assets, css or library folder. Note class site style named after student who created them, We always use mnemonics and consistent nomenclature.
Only true test: A well designed system can be both scaled and maintained over time.

Just loaded an external sheet, they should be in the <head> block, is this h1?

Pre-Tutorial:

  1. Original Data files author github https://github.com/sawmac/css_mm_4e
    To get all zip files use the green drop down button clone or download,
    delete the finished folder, just use the test data.
  2. cloak data folder and zip file. (you have a data/02 data folder)
  3. Copy up data/02 data folder to 02

Tutorial - add inline style to <h1>

  1. Open 02/index.html (Use DOM dialog analyze strucuture),
    best practicies set all foreign server calls to only //server not use the protocol first, if you do you have to match http and https

  2. Create inline style for h1 color: #6A94CC -use split view,
    in split view rolloever color, use CSS color names - find a similar one, try out cornflowerBlue
  3. Set h1 font-size: 3 x width of M i.e. 3em about twice default browser h3=default size; h2 1.2*h3; h1 = 1.2*1.2*default size; h2
  4. Preview in browser, enable and disable the inline rule (right side checkbox) & box model notice height change
  5. Exercise delete the in-line style we just created or preferrably convert to internal style
    select inline rule, right^Click, css styles --> convert inline style to rule, add margin: 0;
    now jump to 7 next tutorial

Tutorial - Create an internal style sheet

  1. add <style> tag to head block
  2. add </style>
  3. inside style block h1 {
  4. add closing french brace }
    Note blocks beginning with { end with }, rules end with ; semicolon, whitespaces are for readability
  5. add rule color:#6194cc
  6. add rule font-size:3em; margin:0;
  7. Live view preview page (design split works) - notice inspect in live view no orange margin,
  8. Add internal rule...
    p {
    font-size: 1.25em;
    color: #616161;
    line-height: 150%;
    margin-top: 10px;
    margin-left: 60px;
    } /* we can do this with css Designer */
  9. Preview live view, have css designer open <style> current, use inspect, notice large left margin.

Tutorial Creating an External Style Sheet

  1. Create external style sheet- styles.css,
    DW CSS Designer, Sources +, Create a new CSS Style Sheet
    In NetBeans to add CSS to a File, right^click folder holding file, and select new Cascading Style Sheet
  2. Add rule...
    html {
    padding-top: 25px;
    background-image: url(images/bg_page.png);
    }
    Use CSS Designer, unlock padding, background icon, browse,
    live view will show background, click styles.css to verify code
  3. Add rule...
    body {
    width: 80%;
    padding: 20px;
    margin: 0 auto;
    border-radius: 10px;
    box-shadow: 10px 10px 10px rgba(0,0,0,.5);
    background-color: #E1EDEB;
    }
    Can paste code into split view; notice all changes in live view
  4. Move all internal rules, to new external file
    with CSS designer click and drag h1, and then p selector to styles.css;
    can also cut (ctrl^x) and paste (ctrl^v)
  5. Verify styles.css (click code button with styles.css selected)
  6. File → Save all work (index.html) will save styles.css
  7. Delete <style> block CSS designer Sources Select -
  8. Implement Google Web Font in head block, before style.css link...
    <link href="https://fonts.googleapis.com/css?family=Varela+Round" rel='stylesheet' ">
    You should be using double quotes
    Notice CSS designer, you have added an @font-face directive Varela Round font family, not being used
  9. Make sure link to styles.css is present
  10. Save and Preview
  11. for h1 use Web font add...
    font-family: 'Varela Round', 'Arial Black', serif;
    font-weight: normal;

  12. Attach same style sheet to another file in 02, (consistent look and feel)
    Open 02/another_page.html
  13. You can use DW attach new style or preferrably complete bullet 14

  14. Copy & Paste Web Font, both lines are...
    <link href='https://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet'>
    <link href="styles.css" rel="stylesheet">
  15. Save and Preview
  16. Styles.css add p font family..
    font-family: "Palatino Linotype", Baskerville, serif;
  17. Add rule for <h2>
    h2 {
    color: #B1967C;
    font-family: 'Varela Round', 'Arial Black', serif;
    font-weight: normal;
    font-size: 2.2em;
    border-bottom: 2px white solid;
    background: url(images/head-icon.png) no-repeat 10px 10px;
    padding: 0 0 2px 60px;
    margin: 0;
    }
  18. Add rule after h2 for .intro class
    .intro {
    color: #666666;
    font-family: 'Varela Round', Helvetica, sans-serif;
    font-size: 1.2em;
    margin-left: 0;
    margin-bottom: 25px;
    }
  19. Note no intro class in HTML, add class="intro" to first paragraph in index.html and another_page.html
    Can do this in live view + (add ID/class) or properties panel class .intro
  20. Save all work, preview in browser
  21. apply same rule to both <p> and <address> tags, add comma , address to p selector...
    p, address { ... }
  22. Save and upload all work

Create index.html page for use on CIM

  1. Create index.html file
  2. Create tutorial 1: index.html and another_page.html
  3. Use Point to file ICON create links to both files.