350 likes | 439 Views
Lab 3: Language Structures. User Interface Lab: GUI Lab Sep. 9 th , 2014. Project 1a. Due now!. Project 2. TBA, will be posted this week. Uses CSS and Bootstrap Due by 10:30am , 9/23 (in two weeks ). Lab 3 goals. Actually cover the languages!
E N D
Lab 3: Language Structures User Interface Lab: GUI Lab Sep. 9th, 2014
Project 1a • Due now!
Project 2 • TBA, will be posted this week. • Uses CSS and Bootstrap • Due by 10:30am, 9/23 (in two weeks)
Lab 3 goals • Actually cover the languages! • The relationships between HTML, CSS, and JS • HTML syntax and terminology • CSS syntax and terminology • JS syntax and terminology
Relationship Between the Languages • HTML defines the structure of the document • CSS defines the way it should be displayed • JS defines how the document should change once its loaded
Some general rules • Document is read by the browser in order: HTML > CSS > JS • Nothing changes after load without JS
HTML • HyperText Mark-up Language (HTML) • Uses a Document Object Model (DOM) • Consists of a series of hierarchical elements
HTML syntax <div> </div>
HTML syntax Element <div> </div>
HTML syntax <div> </div> Opening tag Closing tag
HTML syntax inner HTML <div> </div> Opening tag Closing tag
HTMLsyntax <div class=“container”> </div> Opening tag Attribute name Attribute value Closing tag
HTMLsyntax <div class=“container” id=“target”> </div> Opening tag Attribute Attribute Closing tag
HTMLsyntax Opening tag Attribute Attribute <div class=“container” id=“target”> <div class=“row”> </div> </div> Child Element Closing tag
CSS • Cascading Style Sheets (CSS) • Introduced to make styling HTML easier • Uses a series of selectors that declare different styling properties for HTML elements • Styles will cascade on each other to produce the most complete style
CSSsyntax Declaration .target { color: #ff0000 } Value Selector Property
CSS Selectors • Element Selector • Class Selector • Id Selector
Element Selector p { color:red; } <div> <p> Text that is red. </p> </div> <div> Text that is not red. </div>
.Class Selector .redText { color:red; } .blackText{ color:black; } <div class=“redText”> Text that is red. </div> <div class=“blackText”> Text that is black. </div> <div class=“redText”> Text that is red. </div>
#id Selector #theRedOne { color:red; } <div> Text that is black. </div> <div id=“theRedOne”> Text that is red. </div> <div> Text that is black. </div>
Combined Selectors .redText { color:red; } p.redText { font-size: 50%; } <div class=“redText”> 100% Red Text. </div> <p class=“redText”> 50% Red Text </p> <p> 100% Normal Text. </p>
Defining CSS • External Styles • Internal Styles • Inline Styles cascade in this order
External Styles <head> <link href=“main.css”rel=“stylesheet”type=“text/css/”> </head> child of HTML <head> element CSS file location CSS parsing information
Internal styles <head> <style> .myClass{ background-color: #cccccc; } </style> </head> child of HTML <head> element everything in here is interpreted as CSS
Inline styles everything between “ ” interpreted as CSS can be defined for any element <div id=“mySpecialCase”style=“color: #ffcc99;”> style attribute
JS Syntax varmyNumber = 5; varmyString = “hi”; this is a number this is a string Value Name variabledeclaration
JS Syntax functiondeclaration parameter(s) name function showInput1 (form) { alert(form.input1.value); return false; } function body function call return statement
JS Syntax “has a” relationship varform1 =document.forms[“form1”]; varalsoForm1 = document.forms.form1; form1 == alsoForm1; //results in true.
JS Scoping varmyInt = 5; function doSomething(myString) { alert(myInt + myString); } function doSomethingElse() { varmyOtherInt = 7; alert(myOtherInt+ myString); } global variable parameter valid local variable error
JS-DOM interaction <button id=“target” onclick=“doSomething()”> function doSomething() { alert(“clicked”); } event event handler
JS-DOM interaction <button id=“target” onclick=“doSomething()”> function doSomething() { document.getElementById(“target”); } DOM reference
Defining JS • External Script • Internal Script
External Script <body> <script src=“main.js”type=“text/javascript”></script> </body> child of HTML <body> or <head> element(s) JS file location JS parsing information
External Script • <body> • <script> • function doSomething() { • alert(“reached”); • } • </script> • </body> child of HTML <body> or <head> element(s) everything in here is interpreted as JS
Project 1 grades will be back by next class • Assignment will be posted later this week