IT581: Practicum in Web Development, Summer 2015 (Hybrid)

Lists and external style sheets

Lists in HTML


Unordered Lists - ul and li


Example 1, part A

        <ul>
            <li>Borders</li>
            <li>Lists</li>
            <li>Images</li>
        </ul>
  • Borders
  • Lists
  • Images

Ordered lists - ol and li


Example 1, part B

        <ol>
            <li>Read chapter</li>
            <li>Review notes</li>
            <li>Do homework</li>
        </ol>
  1. Read chapter
  2. Review notes
  3. Do homework

Example 1 in a complete page


Nested lists


Example 2, part A

Notice that the complete UL container is between the opening <li> and closing </li>

        <ul>

            <li>Borders
                <ul>
                    <li>solid</li>
                    <li>dotted</li>
                    <li>double</li>
                </ul>
            </li>
            
            <li>Lists
                <ul>
                    <li>ordered</li>
                    <li>unordered</li>
                </ul>
            </li>

        </ul>

It creates the nested lists:

Example 2, part B

Notice that the complete OL container is between the opening <li> and closing </li>

Browsers may or may not change the number style for the inner list. Firefox 2 and IE 7 do not.

   <ol>
            <li>Some types of borders 
                <ol>

                    <li>solid</li>
                    <li>dotted</li>
                    <li>double</li>
                </ol>

            </li>
            <li>The nested list must be inside the containing list item</li>

 
            <li>Some types of lists
                <ol>
                    <li>ordered</li>

                    <li>unordered</li>
                </ol>
            </li>
           <li>The nested list is inside the containing list item</li>
        </ol>

It creates the nested lists:

  1. Some types of borders
    1. solid
    2. dotted
    3. double
  2. The nested list must be inside the containing list item
  3. Some types of lists
    1. ordered
    2. unordered
  4. The nested list is inside the containing list item

Example 2 in a complete page


List markers


The list-style-type property

type of listlist-style-type
unordered (bulleted) disc, circle, square, none
ordered (numbered) decimal (1, 2, 3), upper-roman (I, II, III), lower-roman (i, ii, iii),
upper-alpha (A, B, C), lower-alpha (a, b, c), none

Example 3

The unordered list styles

        <ul style="list-style-type: square">
            <li>Borders
                <ul style="list-style-type: disc">
                    <li>solid</li>
                    <li>dotted</li>
                    <li>double</li>
                </ul>
            </li>
            
            <li>Lists
                <ul style="list-style-type: circle">
                    <li>ordered</li>
                    <li>unordered</li>
                </ul>
            </li>
        </ul>

Creates the nested lists:

The ordered list styles

        <ol style="list-style-type: upper-alpha">
            <li>Borders
                <ol style="list-style-type: lower-roman">
                    <li>solid</li>
                    <li>dotted</li>
                    <li>double</li>
                </ol>
            </li>
            
            <li>Lists
                <ol style="list-style-type: decimal">
                    <li>ordered</li>
                    <li>unordered</li>
                </ol>
            </li>
        </ol>

Creates the nested lists:

  1. Borders
    1. solid
    2. dotted
    3. double
  2. Lists
    1. ordered
    2. unordered

Example 3 in a complete page


Types of Lists: Description lists

Element Tag Uses & restrictions

Description/Definition List
 which contains
Description Title
 and
Description Description

 <dl>
    <dt>...</dt>
    <dd>...</dd>
 </dl>
  

Used for content that has terms or other titles and associated descriptions or definitions.

  • The dt and dd are contained inside the dl.
  • dl element can only contain dt and dd elements. Nothing else.
  • dt and dd elements must be contained in a dl.
Example - Description list Result
<dl>
 <dt>IT 180 Elements of Web Development I</dt>
 <dd>
An introduction to languages and programming techniques for the World Wide Web, including the Hypertext Markup Language, Cascading Style Sheets and a client-side scripting language. </dd> <dt>IT 180 Elements of Web Development II</dt> <dd>Topics include Web standards and their applications; advanced techniques using XHTML and CSS and selected concepts. </dd> </dl>
IT 180 Elements of Web Development I
An introduction to languages and programming techniques for the World Wide Web, including the Hypertext Markup Language, Cascading Style Sheets and a client-side scripting language.
IT 180 Elements of Web Development II
Topics include Web standards and their applications; advanced techniques using XHTML and CSS and selected concepts.


External style sheets


Example 4A, external style sheet

body {background-color: white; 
      color: black;}

h1  {background-color: #ccc;
     margin: 15px;
     color: red;}

strong {color: red; 
        font-style: italic;}

Using an external style sheet - link

      <link rel="stylesheet"     
            href="URL_of_file" 
            type="text/css" >

Example 4B

    <link rel="stylesheet"     
          href="styles_one.css" >

Complete example 4


Location of external stylesheets

Example 5 - a remote stylesheet

Complete example 5 page


The cascading effect


Example 6A - cascading styles

This example uses the same external style sheet as example 6.1

It also has a stylesheet in the document head.

the rule embedded in the document comes after the one in the external file, and is the one used

    <link rel="stylesheet"     
          href="style_one.css" >

    <style type="text/css">
      h1 { color: #ff0;}
    </style>

link to the complete example 6A page


Example 6 B - cascading styles, continued

This example uses the same external style sheet as example 6.3.a

It also has a stylesheet in the document head.

the order of the link and style tags is reversed from 6.3.a.

the rule in the external file comes after the one embedded in the document, and is the one used

    <style type="text/css">
      h1 { color: #ff0;}
    </style>

    <link rel="stylesheet"     
          href="style_one.css" 
          type="text/css" />

link to the complete example 6B page


Validating stylesheets


Setting (and resetting) styles

There is no such thing as "no styles" in a graphic browser. Each browser is preconfigured with default settings.

  • The default styles may vary from browser to browser. Individual users may also modify some of the default settings such as colors and fonts.
  • It is generally not a good idea to rely on those default settings for your pages. You should control all elements of the document.
  • The best way to ensure that you are not making assumptions is to begin with a set of rules that set all common properties to bare-bones values. This is called a "reset" stylesheet.
  • Here is a model reset stylesheet, from Dr. Chang and the CSS3 Mastery book, adapted from one on Eric Myer's Tools site
  • Begin your stylesheet with @import "reset.css; to import it as the initial set of rules.
  • Or you can make it the first linked stylesheet in your document.
  • If you want to link to this copy, the URL is http://wyrd.hood.edu/~dong/it581/s2015/reset.css
        /* 
        A stylesheet designed to set all properties to a minimal standard.
        It eliminates unpredictable variations caused by different browser defaults.
        
        You can use it by including the following line at the beginning of your own stylesheet:
        
           @import "http://wyrd.hood.edu/~dong/it581/s2015/reset.css";
        
        Then in your custom stylesheet add rules to create the design you want.  
        */
       
        html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote,
        pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd,
        q, s, samp,small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt,
        dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot,
        thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption,
        footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark,
        audio, video {
        	margin: 0;
        	padding: 0;
        	border: 0;
        	outline: 0;
        	font-size: 100%;
	        font-weight: normal;
	        font-style: normal;
        	vertical-align: baseline;
        	background: transparent;
        }
        article, aside, details, figcaption, figure, footer, header, hgroup, 
        menu,nav, section {
            display: block;
        }
        body {
            line-height: 1.2;
        }
        
        ol {
            padding-left: 1.4em;
            list-style: decimal;
        }
        ul {
            padding-left: 1.4em
            list-style: square;
        }
        table {
            border-collapse: collapse;
            border-spacing: 0;
        }


Div and span elements

  • Most elements in an XHTML document have an implied structural meaning.
    • h1, h2, ... are headlines, similar to chapter and section headings or topic headings in an outline
    • p is a paragraph, which has meaning as a coherent unit of information
    • strong means something is strongly emphasized
  • Sometime you just want to group some of the document content
    • without any special meaning
    • where existing tags aren't really suitable
    • usually for puposes of styling
  • div and span elements provide a generic mechanism for adding structure to documents
  • they define content to be inline (span) or block-level (div) but impose no other meaning on the content
  • In formal terms, they are semantically empty.
  • you can use these elements in conjunction with style sheets

The block element <div>

  • <div> lets you mark a block.
  • <div> is a container; it must be closed with </div>
  • A div starts on on a new line because it is a block
  • It is valid to nest other block elements, such as h1 or p or ul, inside <div>.

Example 7 - <div>

  • Each <div> contains an h2 heading and two paragraphs.
  • The div creates groupings
         <div> 
           <h2>First DIVision</h2> 
           <p> A short paragraph of text</p> 
           <p> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed at quam non neque vestibulum pretium.</p> 
         </div> 
         
         <div> 
           <h2>Second DIVision</h2> 
           <p> Another short paragraph of text</p> 
           <p> Donec blandit. Praesent eget lectus. Sed nisi. Pellentesque tempor imperdiet enim. Pellentesque mattis elit eget eros. Sed adipiscing ligula nec mauris.</p> 
         </div> 
  • A style rule give each division a yellow background, red border, and some blank space around the outside.
  • The rule will be in a style section in the head.
       div {background-color: yellow; 
            border: solid medium red;
            margin: 10px;}

link to the complete example 7 page. Be sure to view the source code.


The inline element <span>

  • <span> is similar to <div>
  • it is an inline element, not a block.
  • It is used to group characters within a block.
  • it is commonly used with classes so the groupings can be given distinct styles.
  • it could also be used with id to create a target in the page

Example 8 - <span>

   <p>Some words in <span class="one">red</span>, 
     <span class="two">blue</span>, 
     and <span class="three">lime green</span> text.</p>
     
    <p>Another <span class="one">span belonging to class one span </span>, 
     and an additional <span class="two">span with class two </span>, 
     and <span class="three">some more class three span </span> content.</p>
  • each span belongs to a class so it can be given a distinct style.
    span.one {color: red}
    span.two {color: blue}
    span.three {color: lime}

link to the complete example 8 page. Be sure to view the source code.


Guidelines

  • If items are part of a list (hotlist of links; to-do list; hit list; whatever list), use a list structure to present them. Don't just create the appearance of a list with lines and breaks.
  • Use an unordered list if the items do not have a specific order.
  • Use an ordered list if the items do have an intended order.
  • Use external stylesheets to share style rules among several documents and to help keep presentation separate from structure.
  • Use div and span elements to for blocks and inline elements that do not have any specific structural meaning.
  • Use a class to be able to use a style rule with several different element in a document.
  • Always validate your stylesheets.
Comments to: dong@hood.edu
Last Modified: 08 July 2015. 12:51