Documentos de Académico
Documentos de Profesional
Documentos de Cultura
HTML5 & CSS3.0 Part 1: Using HTML and CSS to Create a Website Layout
Fall 2011, Version 1.0
Table of Contents
Introduction ...................................................................................................................................3 Downloading the Data Files ..........................................................................................................3 Requirements..................................................................................................................................3 About Notepad++ ........................................................................................................................3 Notepad++ Interface ...............................................................................................................4 About HTML & CSS .....................................................................................................................4 HTML5 .......................................................................................................................................4 Studying Basic Tags ...............................................................................................................4 Structure of HTML Tags ........................................................................................................5 Opening and Closing HTML Tags .........................................................................................5 Head and Body Tags ..............................................................................................................5 Cascading Style Sheets (CSS).....................................................................................................5 Classes & IDs ........................................................................................................................5 CSS Selectors .........................................................................................................................5 Creating a New Web Page .............................................................................................................6 Creating our Home Page .............................................................................................................6 Basic Website Structure .........................................................................................................7 Setting the Page Title .............................................................................................................7 Saving the Page ......................................................................................................................7 Creating a Section for CSS Styling Tags ....................................................................................8 Indentation...................................................................................................................................8 Setting the Background Color .....................................................................................................9 Creating the Wrapper ..................................................................................................................9 Creating a class for the Wrapper ............................................................................................9 Centering Page Elements .................................................................................................10 Checkpoint One.........................................................................................................................10 Creating the Website Structure within the Container .............................................................11 Adding a Banner and a Navigation Bar ....................................................................................11 Adding a Navigation Bar ..........................................................................................................12 Checkpoint Two ........................................................................................................................13 Adding the Main Content Containers ........................................................................................13
For additional handouts, visit http://www.calstatela.edu/handouts. For video tutorials, visit http://www.youtube.com/mycsula.
Adding the Main Content Div ...................................................................................................13 Adding the Footer .....................................................................................................................14 Adding Text to the Page ..............................................................................................................15 Checkpoint Three ......................................................................................................................15 Basic Styling of Text.................................................................................................................16 Appendix .......................................................................................................................................17
Title
Introduction
Websites can be created by using one of many coding languages (e.g., HTML, JSP, PHP, ASP, ASP.NET, or Perl). Among those languages, HTML is the most basic text-based language that has been used in Web design since 1989. HTML consists of two parts: 1) content that will be displayed in a web browser and 2) markup or tags, which are encoded information that is generally hidden from web page viewers. This three-part workshop series will help participants create a basic website using fundamental HTML knowledge that they can build on with more advanced techniques. The first part will introduce the basics of web design that includes using divisions to arrange the page layout, menu bar to link multiple pages and CSS 3.0 to enhance web page elements
Requirements
A text editor, preferably Notepad++ or something similar. Notepad that is provided with Windows will also work. o Notepad++ http://notepad-plus-plus.org/download http://portableapps.com/apps/development/notepadpp_portable (Portable version that can be placed on a flash drive) A recent web browser, e.g., Mozilla Firefox, Google Chrome or Internet Explorer 9. o Google Chrome http://www.google.com/chrome/intl/en/landing_chrome.html?hl=en o Mozilla Firefox http://www.mozilla.com/en-US/firefox/new/ o Internet Explorer 9 (Only on Windows 7 and Windows Vista Service Pack 2) http://windows.microsoft.com/en-US/internet-explorer/downloads/ie
NOTE: Anything below Internet Explorer 9 is not compatible with the new HTML5 features. While any on the list above is acceptable, this handout is developed based on the steps administered in Notepad++ and Mozilla Firefox.
About Notepad++
Notepad++ is a lightweight, but powerful text editing tool. It is built primarily for programming, not writing essays. It has built in tag highlighting and automatic indentation which helps improve organization and readability.
Title
Notepad++ Interface
Menu Bar Tab Bar Line Number s Tool Bar
Text Area
Status Bar
Figure 1 - Notepad++ Interface
HTML5
HTML5 is still a work in progress and has been since June of 2004. Most of the tags that were compatible in previous versions of HTML are still compatible. However, they are no longer used because better and cleaner methods have since been found. HTML5 is still not final, but is already making a huge impact on the web.
Title
tag. Instead, they are created in their own style tag. The <style> tag can be placed in the <head> section of your html page (internal), or it can be placed in a separate CSS file and then imported (external).
CSS Selectors
CSS selectors offer various ways to select your HTML tags for styling. These extra selectors are used to reduce the need to create a new classes or IDs for every tag created, and results in cleaner code.
NOTE: For more information on CSS selectors, visit http://www.w3.org/TR/CSS2/selector.html.
Table 1 CSS Selectors
Selector
Example of Syntax
Description
Example of Selection
Class
.box{Attributes Here}
ID
#box{Attributes Here}
Tag Selector
p{ Attributes Here }
Will affect any tag with the class wrapper applied to it. Will affect any tag with the ID wrapper applied to it. This selector will affect all <p> tags in the HTML document. This selector will affect any <a> tag that is a child element of a <p> tag.
<p class=box> This text is affected. </p> <p id=box> This text is affected. </p> <p> This text is affected. </P> <p> <a> This text is affected. </a> </p>
Child Selector
Pseudo Selector
Will only apply defined <a>Hover over me</a> style on mouse hover.
Title
Title
Any CSS that needs to be added to the page, will be added in-between the style tags.
Title
Indentation
Indenting the source code of any computer language is absolutely crucial. It makes the code cleaner and much easier to read. [Tab] is most often used to indent source code. As a rule of thumb, you should indent every time you insert an element into another element, this is known as nesting. Example: <body> <p> This is a nested paragraph. </p> </body> In this small scale example, the paragraph tag (<p>) is nested in the <body> tag. Every element in the page is nested in the <html> tag aside from the <!doctype>, which always resides at the very top of the page.
Figure 4 - Make sure the opening and end tag are on the same vertical line
4. Type background-color:#cccccc; (No quotes) This defines the background color with the hexadecimal value for light grey. 5. To see the changes, save the file by clicking File, then Save, or by pressing Ctrl + S simultaneously. Also, be sure to refresh the page in the browser.
Title
1. Place the cursor between the <body> tags and type: <div class=wrapper> </div> 2. Press [Enter] a couple of times to allow some space in-between the newly created tags for content. 3. Be sure to apply appropriate indentation accordingly.
Title
10
NOTE: This is currently the most effective and compatible way to center elements. This uses very common CSS that is unlikely to ever be deprecated.
Checkpoint One
This is the first of three checkpoints within this handout. At each checkpoint, make sure that the document that is being created is similar enough (some discrepancies are acceptable). The code should look similar to Figure 5 Checkpoint One.
Title
11
Technically speaking, the banner is actually at the top of the page at this point. However, it has no style applied to it, making it invisible. Lets add some style: 2. Next, navigate to the CSS portion of our web page and underneath the defined class of wrapper, add a new one named div.banner div.banner{ }
NOTE: Remember to match the indenting of the previous classes.
3. In-between the curly braces, type: width: 750px; height: 90px; position: relative; top: 0px; margin-left: auto; margin-right: auto; border: 1px solid black;
NOTE: position:relative; is a bit more complex and is used to give you more of a choice on how you want the positioning of your element to react to its surroundings (more later). top:0px; moves the element so that the top of the element is at the top of the parent element, which in this case is the wrapper.
2. Next, navigate to the CSS portion of our web page and underneath the defined class of banner, add a new one named. div.nav{ } 3. In-between the curly braces, type: background-color: #5C5C5C; width: 750px; height: 30px; margin-left: auto;
Title 12
margin-right: auto; position: relative; top: 3px; border: 1px solid black;
NOTE: Since we declared position:relative, our navigation bar will appear naturally after the banner. We add 3 pixels of space between the top of the navigation bar and the bottom of the banner.
Checkpoint Two
Your code should look similar to what is seen below.
NOTE: The code shown below is only the code edited since checkpoint 1. For the full code, refer to the data file checkpoint_2.html.
Title
13
1. In-between the div tags with the class wrapper applied to it and below the div tags with the class nav applied to it, type: <div class=main></div>
NOTE: Be sure that you close the main div tag on the same line for clarity.
2. Next, navigate to the CSS portion of our web page and underneath the defined class of nav, add a new one named div.main div.main{ } 3. In-between the curly braces, type: position: relative; top: 6px; width: 750px; height: 600px; margin-left: auto; margin-right: auto; border: 1px solid black; background-color: white;
NOTE: Since we declared position:relative, our navigation bar will appear naturally after the nav. We add 6 pixels of space between the top of the main content box and the bottom of the nav.
2. Next, navigate to the CSS portion of our web page and underneath the defined class of nav, add a new one named div.footer div.footer{ } 3. In-between the curly braces, type:
Title
14
background-color: black; height: 180px; width: 752px; margin-left: auto; margin-right: auto; position: relative; bottom: 8px; z-index: 1; color: white;
NOTE: z-index:1; gives our footer the z-index of 1, meaning that it will be above all other elements. z-index is a way to change the layering of elements without having to rearrange our div tags. Elements without z-index defined in the style default to 0.
Checkpoint Three
Your code should look similar to what is seen below.
Title
15
NOTE: The code shown below is only the code edited since checkpoint 2. For the full code, refer to the data file checkpoint_3.html.
text-decoration: underline; o text-decoration: line-through; o text-decoration: overline; color: red; o color: blue; o color: #00FF00; --- Hexadecimal values also work to specify colors. font-size:20px;
16
Appendix
Table Commonly Used HTML Color Codes
Color Code Color Code Red #FF0000 White #FFFFFF Turquoise #00FFFF Light Grey #C0C0C0 Light Blue #0000FF Dark Grey #808080 Dark Blue #0000A0 Black #000000 Light Purple #FF0080 Orange #FF8040 Dark Purple #800080 Brown #804000 Yellow #FFFF00 Burgundy #800000 Pastel Green #00FF00 Forest Green #808000 Pink #FF00FF Grass Green #408080 For more color code list, visit: Webmonkey - http://www.webmonkey.com/reference/color_codes/ Colourlovers - http://www.colourlovers.com/blog/2007/06/30/ultimate-html-colorhex-code-list/ ComputerHope - http://www.computerhope.com/htmcolor.htm
Table 1 Commonly Used HTML Tags
Tag
Name
Description
<a> <b> <body> <br> <em> <form> <h1> <head> <hr> <html> <i> <img> <input> <li> <menu> <ol> <p> <table> <td> <th> <title> <tr> <u> <ul>
anchor bold body of HTML document line break emphasis form heading 1 heading of HTML document horizontal rule hypertext markup language italic image input field list item menu ordered list paragraph table table data table header document title table row underline unordered list
Make hyperlinks Bold the text Where to start the document and place the HTML codes Force to change line Emphasis the content Insert a form inside the web page Heading Size Contains information about the page Create a horizontal line Begins the HTML document Italic the text Image Insert a input field Create a listed item in an unordered or ordered list Insert a menu in a web page Numbered the list Create a line break and a space between lines. Insert a table inside a web page The cell of a table The header of a table The title in the title bar of the browser The row of a table Underline the text Bullets the list
Title
17