0ab2cf26040de76b9aa97215eeb2c70c.ppt
- Количество слайдов: 99
HTML 5 Seminar Ga Tech March 31, 2012 Barbara Ericson Barbara Fox
We all start here. . . http: //www. datamation. com/img/2009/07/art-programming. jpg
CSS for styling colors, position, fonts "HTML 5" HTML tags and attributes whales. htm
Whales are mammals.
. . . and it looks like this
What will I have to change when moving from HTML 4 to HTML 5?
HTML 4 vs. HTML 5
HTML 4 vs. HTML 5
HTML 4 vs. HTML 5
HTML 4 vs. HTML 5
HTML 4 vs HTML 5 whales. htm • simplifies document markup wstyle. css • Must use CSS for all appearance styling • CSS 3 • adds styles like drop shadows and rounded borders • adds selector options • adds new element tags for greater semantic content • deprecates tags and attributes that were used primarily for styling appearance vs. semantic content whales. js API's which add Java. Script functionality: Video, Canvas, Local Storage, Audio, Forms, Drag & Drop, Geolocation, Sockets, Web Workers, Offline Caching
Deprecated HTML tags
Deprecated HTML attributes Attributes removed from most elements: align background bgcolor border cellpadding cellspacing width For complete list see: http: //www. tutorialspoint. com/html 5_deprecated_tags. htm
Whales are mammals.
"HTML 5" Java. Script API's l l Geolocation Forms identify browser location can require certain fields filled in; verify email, URL's or phone numbers l Web Workers manage multiple scripts running concurrently and in the background to avoid lags l l Local Storage Canvas store info on desktop computer draw text, images, lines, circles, rectangles, patterns, and gradients l l Audio & Video more advanced features Offline Web Apps Applications which will work even when not connected to the web
Lab 1: Convert HTML 4 to HTML 5 l l Copy Lab 1. zip to your computer & unzip it Using code from Power. Point slides: l l l Convert whale. htm to HTML 5 Move color styling to CSS View whale. htm in your browser to verify it renders properly
Introduction to HTML Skip HTML, jump to Lab 1
HTML Tags l l l Begin with < End with > Tagname in the middle < tagname > Identify the structure of the content (paragraph, image, link, heading, etc. ) If a tag contains content (text, other tags, etc. ) then it will have a closing tag
HTML Attributes l l l Provide additional information Located inside an opening tag Syntax attributename="value of attribute"
. . . . . ." src="https://present5.com/presentation/0ab2cf26040de76b9aa97215eeb2c70c/image-19.jpg" alt="Basic HTML Structure . . . . . ." /> Basic HTML Structure . . . . . . The doctype declaration is not usually referred to as a tag. Which are tags? Name the attribute: lang What is the value of that attribute? "en"
. . . . . ." src="https://present5.com/presentation/0ab2cf26040de76b9aa97215eeb2c70c/image-20.jpg" alt="Basic HTML Structure . . . . . ." /> Basic HTML Structure . . . . . . required first line according to HTML 5 HTML web page in English top portion contains
Common text tags in
paragraph
HTML Miscellaneous Comments Nesting Tags should be nested inside of each other like nesting dolls. To opening tag and closing tag create a "box" that contains other information.
Beginning of a paragraph
- Orca
- Beluga
Try It Nesting Check This HTML is not nested properly. Write down the correct HTML. Indent to make the nesting more clear. .
- Pizza Cake
- Cookies
Nesting Solution
- Pizza
- Cake
- Cookies
- Sushi
Spacing in HTML Block tags start on a new line and do a line break when finished:
,
Images l l Embed jpg, gif, and png images into web page Image tags require the use of attributes n src - locatio of image file y t will displa ate text tha any reason alt - altern display for nnot if picture ca src - location of image file o n internet beg ins with http: / / alt - alternate text required for federal ac cessibility law s
Hyperlink aka anchor aka link l A hyperlink is text or an image that you can click on to jump to a new document (or a different part of the current web page) internet sites usually begin with http: // Click here to go to Google href - U RL to w ebsite local sites do NOT begin with http: // Click here to go to the local web page called whales. htm Great site to learn about web design targe t = "_blank" - opens the w eb page in a NEW window
Lab 2 Create website Create a 2 -page web site about another teacher in the room 1. l l 2. 3. 4. 5. Create new folder/link called lab 2 to hold the files Create home page: index. htm Create second page: interests. htm Add proper HTML 5 info in
Common HTML Attributes src="playlist. js" src="marathon. jpg" embeds the contents of this file into the web page href="playlist. css" href="http: //google. com" hyperlink reference to an external file id="first" a unique identification for an element so it is easy to refer to it with HTML, CSS, or Java. Script class="whale" an identifier than can refer to multiple elements to make it easy to refer to those elements with HTML, CSS, or Java. Script
Tables
Tables - additional tags
Tables - HTML 5 attributes Removed width, cellspacing, cellpadding, and others Only supported attribute is: border="" border=1 No border on
Tables - add'l context tags
Tables - colgroup l Create groups columns for styling
Lab 2 B Add a table l Add a table to the teacher website Note: This page will still have boring black text and the pictures will be sized poorly. That's ok! We can dress it up later with CSS.
Form Elements - text + button Small Small
Form Elements - radio buttons bicycle bicycle
Form Elements check box and Submit button
Lab 2 C Add a form to your teacher website which includes: l input type="text" (ask for student name) l button (Add a Song, Add a Class, etc. ) l radio buttons (age, gender, etc. ) l checkboxes (favorite foods) l submit button Note: This page will still have boring black text and the pictures will be sized poorly. That's ok! We can dress it up later with CSS.
Div
Div div id="info" div id="photos"
Div #photos { height: 250 px; width: 650 px; background-color: gray; border: 10 px solid black } #photos img { margin: 20 px; border: 5 px solid white; height: 200 px } only div id="photos" is affected by the CSS styling
Solution
Introduction to CSS Skip CSS, jump to Lab 2
CSS l l Cascading Style Sheets Control the appearance or style of the web page l l l color, font, border width, height, position margin, padding
CSS l Inline CSS l l l Internal CSS aka Embedded CSS l l affects one line of HTML located within an HTML tag affects one web page located in the
CSS - w 3 schools. com
CSS - inline l Inline CSS l l l affects one line of HTML located within an HTML tag no selector since it is inside a tag
CSS - internal l Internal CSS aka Embedded CSS l l l affects one web page located in
CSS - external l External CSS l l l affects every web page that include to the CSS file Do NOT specify
CSS with classes l l The HTML attribute class=" " is used to identify multiple HTML elements so Java. Script, CSS, and other HTML can refer to them easily. classname is the CSS selector for a class . whale { color: red; } Another name for a killer whale is an orca
CSS 3 - border-radius #whale { width: 400 px; height: 250 px; background-color: Light. Sky. Blue; padding: 15 px; border-radius: 20 px; } #whale img { width: 50%; border: 15 px solid gray; border-radius: 15 px }
CSS 3 - drop shadows #blurred { background-color: Light. Sky. Blue; box-shadow: 10 px 5 px gray; } #sharp { background-color: Light. Sky. Blue; box-shadow: 10 px black; }
Lab 2 D l l Create a CSS file called lab 2. css in the labs folder Add the following line in the
Sample lab 2. css /* lab 2. css */ body { background-color: gray } h 2 { color: red } h 3 { text-align: center} img { border: 9 px solid blue; width: 200 px } p { font-style: italic } a: hover {color: blue} /* hover link color */
What can you do with Java. Script?
Three places to add Java. Script
Make a statement Store a value in a variable Add comments var temp=98. 6; // fahrenheit var first. Name = "Adam"; var last. Name = "Zigler"; temp = (temp - 32) * 5 / 9; var fullname = first. Name + " " + last. Name; Do math Concatenate strings var random. Num = Math. random(); var count=5; count=count+1; Use functionality built into Java. Script Add one to an existing variable
Pop up an alert window alert("Please enter a song");
Try It Simulate a baseball game. Create home. Score with value of 10 Create visitor. Score with value of 8. Pop up an alert stating "Game Over" Challenge: Pop up an alert that prints the current scores Hint: "n" prints a newline
Do things more than once (while loop) bean. Counter = 5; while (bean. Counter > 0 ) { alert("Dropped a bean"); bean. Counter = bean. Counter - 1; }
Do things more than once (for loop) var weight=130; for (scoops = 0; scoops < 10; scoops++) { weight=weight+1; } This loop will execute 10 times ( 1 st Iteration: scoops = 0 2 nd iteration: scoops = 1. . . 9 th iteration: scoops = 8 10 th iteration: scoops = 9 then scoops=10 so loop exits weight=131 weight=132 weight=139 weight=140
Try It Simulate strikeouts with a for loop. Alert popups that say: Strike 1 Strike 2 Strike 3 You're out
Solution
Make decisions and get input from popup prompt var name=prompt("Please enter your name", "Jane Doe"); if (name!=null && name!="") { alert("Thank you, " + name) } else { alert("Name entered improperly"); } != "" && not equal empty string AND (both conditions must be true)
Java. Script code samples http: //www. blogohblog. com/wp-content/pop/2008/07/funnyjavascript. gif
Before changing DOM, page must be completely loaded This function changes the value of an existing HTML element function init() { var nm = document. get. Element. By. Id("name"); nm. inner. HTML = "Jessie"; } window. onload = init;
Create a function This function changes the value of an existing HTML element function show_prompt() Function name { var name=prompt("Please enter your name", "Jane Doe"); if (name!=null && name!="") greet refers to element with id="greetings" { var greet = document. get. Element. By. Id("greetings"); greet. inner. HTML = "Hello, " + name ; } } inner. HTML changes the contents of the element with id="greetings"
Try It Prompt the user for their hometown and then display the result on the webpage.
Potential Solution
Respond to a button click
0; i--) { newtext = newtext + " " + i; } blast. inner. HTML = newtext; } window. onload = countdown; // no parentheses
Arrays var temp. By. Hour = new Array(); temp. By. Hour[0] = 59. 2; temp. By. Hour[1] = 60. 1; temp. By. Hour[2] = 63; temp. By. Hour[3] = 65; temp. By. Hour[4] = 62; var temps = [59. 2, 60. 1, 63, 65, 62]; index 0
Arrays // Add to existing array temp. By. Hour[5] = 61; // Get the value of one element of the array var message = "The temp at 5 pm was " + temp. By. Hour[5]; // Retrieve the size of the array var num. Items = temp. By. Hour. length; p. 67
Creating an object with properties. . . iterating through the properties
Webville Tunes - Chapter 3 Ask user to enter songs and then add them to a songlist
Lab 3 l l Copy the folder lab 3 to your computer Assignment: Add a line to the bottom of the web page which displays the total number of songs entered into the play list Hints: 1. Edit lab 3 -playlist. htm and add an
Lab 3 (cont. ) 3. 4. 5. 6. 7. 8. Edit lab 3 -playlist. js Create a global variable called total_songs and set its initial value to 0 Find the part of the code that gets executed when a song is successfully entered. Inside that block of code, immediately after the new
Solution - Lab 3 lab 3 -playlist. html
Solution - Lab 3 lab 3 -playlist. js var total_songs = 0; . . . function handle. Button. Click() { var text. Input = document. get. Element. By. Id("song. Text. Input"); var song. Name = text. Input. value; if (song. Name == "") { alert("Please enter a song"); } else { alert("Adding " + song. Name); var li = document. create. Element("li"); // create new object li li. inner. HTML = song. Name; // give it text of user entered song. Name var ul = document. get. Element. By. Id("playlist"); // create new object attached to id=playlist ul. append. Child(li); // append the li object to end of ul id=playlist // Solution Additions/////////////////// total_songs=total_songs+1; var s. Total = document. get. Element. By. Id("num. Songs"); s. Total. inner. HTML = "Total songs: " + total_songs. to. String(); }
Supplemental Lab 4 l Copy the folder called lab 4 to your computer l Add another input text box and button which creates a list of Musicians. Make it work just like the Song list. Hints: l Edit lab 4 -playlist. htm and copy the form used for songs. Change the data to reflect musicians. l Edit lab 4 -playlist. js and add code to allow users to also enter a list of musicians (note: solution can be found in the folder lab 4 -solution)
Solution - Lab 4 lab 4 -playlist-solution. html
Solution - Lab 4 lab 4 -playlist-solution. js function init() {. . . var mbutton = document. get. Element. By. Id("add. Musician. Button"); mbutton. onclick = handle. Musician. Click; } function handle. Musician. Click() { var text. Input = document. get. Element. By. Id("musician. Text. Input"); var musician = text. Input. value; if (musician == "") { alert("Please enter a musician name"); } else { alert("Adding " + musician); var li = document. create. Element("li"); li. inner. HTML = musician; var ul = document. get. Element. By. Id("musicianlist"); ul. append. Child(li); } }
,
,
Inline tags will display beside each other: , , To force a newline (i. e. line break): HTML treats multiple spaces as one space. Add extra spaces with:
table row column or row heading cell (table heading) regular cell (table data) 1 st row - table headings 2 nd, 3 rd, & 4 th row - table data
with No CSS Styling with CSS Styling
Whale Length Weight Blue Whale 100 feet 150 tons Sperm Whale 60 feet 50 tons Killer Whale 30 feet 5 tons
Whale Length Weight . . . Blue Whale 100 feet 150 tons
with No CSS Styling with CSS Styling
Whale Length Weight Blue Whale 100 feet 150 tons Sperm Whale 60 feet 50 tons Killer Whale 30 feet 5 tons
with CSS Styling
Whale Length Weight Blue Whale 100 feet 150 tons Sperm Whale 60 feet 50 tons Killer Whale 30 feet 5 tons
html head title body h 1 ul id="playlist" li id="song 1" li id="song 2" li id="song 3" p. 82
/* playlist. js */ window. onload = init; function init() { var button = document. get. Element. By. Id("add. Button"); button. onclick = handle. Button. Click; } function handle. Button. Click(e) { var text. Input = document. get. Element. By. Id("song. Text. Input"); var song. Name = text. Input. value; alert("Adding " + song. Name); if (song. Name == "") { alert("Please enter a song"); } else { alert("Adding " + song. Name); var li = document. create. Element("li"); li. inner. HTML = song. Name; var ul = document. get. Element. By. Id("playlist"); ul. append. Child(li); } }
, add code which. . . Adds one to the total_songs variable Creates a variable called s. Total to hold the element identified by id="num. Songs" Change the inner. HTML value of s. Total to "Total songs: " + total_songs. to. String() (note: solution can be found in the folder lab 3 -solution)