Web GUI Development CSE5544 We Will Focus on the Client-Side
Total Page:16
File Type:pdf, Size:1020Kb
Web GUI Development CSE5544 We will focus on the client-side. • Client-side: HTML, CSS (Bootstrap, etc.), JavaScript (jQuery, D3, etc.), and so on. Background • Server-side: PHP, ASP.Net, Python, and nearly any language (C++, C#, Java, etc.) • HTML – Structure/Content • CSS – Presentation/Style • JavaScript – Behavior Outline • Recall HTML+CSS Basic (warm-up). • HTML element, attribute, style, selector (type, id, class). • HTML+CSS for Web GUI. • HTML layout and commonly used elements. • Bootstrap (HTML+CSS framework with design template). • JavaScript to make Web GUI (HTML pages) dynamic and interactive. • JavaScript basic: function, array, object, etc. • HTML JavaScript DOM: manipulate HTML contents. • jQuery: JS library to simplify HTML contents manipulation and so. • D3: JS library to visualize data using HTML+SVG+CSS. HTML Element • HTML (Hyper Text Markup Language) is the standard markup language for creating Web pages. • HTML describes the structure of Web pages. • HTML elements are the building blocks of HTML pages, and are represented by tags (to render page contents by your browsers). • W3C recommends lowercase in HTML, and demands lowercase for stricter document types like XHTML. HTML Attribute • Attributes provide additional information about HTML elements, e.g., define the characteristics of an HTML element. • Attributes are always specified in the start (opening) tag. • Attributes usually come in name/value pairs, e.g., name="value”. • Both double quotes (more common) and single quotes around attribute values can be used. • In case attribute value itself contains double quotes, it is necessary to use single quotes. HTML Attribute cont. • The four core attributes that can be used on the majority of HTML elements (although not all): • id: uniquely identify any element within an HTML page. • title: provide additional "tool-tip" information. • class: associate an element with a style sheet, and specify the class of element. • style: specify the styling (like color, font, size, etc.) within the element. • We will revisit these attributes soon later. • style: inline css styles. • class and id: HTML selector. CSS Style • CSS (Cascading Style Sheets) describes how HTML elements are to be displayed, e.g., layouts, colors, fonts, etc. • CSS can control the style of multiple elements, pages, or sites all at once. The separation of HTML from CSS can save a lot of work. • CSS can be associated with HTML elements in 3 ways: • External - by using an external CSS file • Internal - by using a <style> element in the <head> section • Inline - by using the style attribute in HTML elements CSS Style cont. 2 Internal <head> 1 External <style> h1 {color: blue;} #head1 {color: blue;} .head1 {color: blue;} </style> </head> <body> <h1>This is a heading</h1> </body> 3 Inline <head> <link rel="stylesheet" href="styles.css"> </head> https://internetingishard.com/html-and-css/hello-css/ <h1 style="color:blue;">This is a Blue Heading</h1> HTML Class • The class is an important attribute of HTML elements. Elements with the same class can have equal styles. • The class name can be used (by CSS and JavaScript) to perform certain tasks for a group of elements with the specified class name. Notice the dot (.) prefixing the class name. This distinguishes class selectors from the type selectors and ID selectors. Class selector Type selector ID selector https://www.w3schools.com/html/tryit.asp?filename=tryhtml_classes_css HTML ID • The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document). • The id value can be used (by CSS and JavaScript) to perform certain tasks for a unique element with the specified id value. Notice the hash character (#) prefixing the ID value. This distinguishes ID selectors from the type selectors and class selectors. ID selector Type selector Class selector https://www.w3schools.com/html/tryit.asp?filename=tryhtml_classes_css More… Descendant selectors Pseudo classes • Target only those elements that are inside of another • Mainly for links and buttons. element. For example, only phrases (<em>) in • For example - :link :visited :hover :active paragraphs of a class of .synopsis a:hover { • Note you can nest descendant selectors as deep as color: aqua; you want, but life gets confusing if too much. text-decoration: underline; .synopsis em { font-style: normal; } } https://internetingishard.com/html-and-css/css-selectors/ And More… CSS Specificity CSS Cascade • Specificity: which rules take precedence in CSS when • Generally, web-standard browsers will rank several rules could be applied to the same element . a style’s significance in this order: • Order matters for css rules: top-to-bottom and can result in overriding. • Some selectors will override other ones. For instance, ID selectors have higher specificity than class selectors. https://cssway.thebigerns.com/special/master-item-styles/ HTML Layout • Design your HTML pages and arrange the contents. • Websites often display contents in multiple columns (like a magazine or newspaper). • HTML layout techniques to create multicolumn layouts, e.g., • HTML tables (unrecommended), CSS float, CSS flexbox/grid (new), CSS framework (Bootstrap) https://www.w3schools.com/html/html_layout.asp HTML Layout cont. • Some web GUI design patterns (for your reference). (Useful) HTML Elements (1) • The <input> element indicates an input field where the user can enter data. Note that the <input> tag has no end tag in HTML. • The <input> element can be displayed in several ways, depending on the type attribute. • Syntax: <input type="value"> A one-line text First name: <input type="text" name="firstname” value="Mickey"><br> input field Last name: <input type="text" name="lastname"> Radio buttons let a user <input type="radio" name="gender" value="male"> Male<br> select ONE of a limited <input type="radio" name="gender" value="female” checked> Female<br> number of choices <input type="radio" name="gender" value="other"> Other ChecKboxes let a user <input type="checkbox" name="vehicle1" value="Bike" checked> I have a bike<br> select one or more <input type="checkbox" name="vehicle2" value="Car"> I have a car<br> options of a limited <input type="checkbox" name="vehicle3" value="Boat" checked> I have a boat<br> number of choices A clicKable button <input type="button" value="Click me" onclick="msg()"> <script> (mostly used to activate Will address the JavaScript part later a JavaScript script) function msg() { alert("Hello world!"); } </script> HTML Elements (2) • More attribute values for <input type="value"> • color – a color picker • date (or datetime-local) - date control (year, month, day) • file - a file-select field and a ”browse" button (for file uploads) • email - a field for an e-mail address • password - a password field • number - a field for entering a number (you can also set restrictions on what numbers are accepted) • range - a range control (like a slider control) • hidden - a hidden field (not visible to a user) • submit - a submit button (submit the form data to a form-handler) • reset - a reset button (reset all form values to default values) Notes about forms and PHP: • The HTML <form> element defines a form that is used to collect user input. The form data can be submitted to a form-handler, which is typically a server page (e.g., PHP) with a script for processing input data. • PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is generally used to collect form data, control user access, approach and manipulate files on the server and data in the database, generate dynamic page contents, etc. If you click the "Submit" button, the form-data • We won’t go into PHP here, but you are welcome to explore more! will be sent to a page called "/action_page.php" HTML Elements (3) • The <select> element defines a drop-down list; and the <option> element defines an option that can be selected. One or multiple options can be selected. <select name="cars"> <select name="cars" size="5" multiple> <option value="volvo">Volvo</option> <option value="volvo” selected>Volvo</option> <option value="saab" selected>Saab</option> <option value="saab" selected>Saab</option> size=5 <option value="fiat">Fiat</option> <option value="fiat">Fiat</option> <option value="audi">Audi</option> <option value="audi">Audi</option> </select> </select> • The <textarea> element defines a multi-line input field (a text area). <textarea name="message" rows="5" cols="30">The cat was playing in the garden. His name is Pipi, and he is in grey rows=5 and white. He is naughty, fluffy, and warm!</textarea> cols=30 • The <button> element defines a clickable button (similar usage with <input type=”button">). <button type="button" onclick="msg()">Click Me</button> <script> function msg() { alert("Hello world!"); } </script> OR <button type="button" onclick="alert('Hello World!')">Click Me</button> Bootstrap – to make HTML+CSS easier • Bootstrap is the most popular HTML and CSS (and JavaScript) framework for developing responsive websites. • Bootstrap makes your front-end web development easier and faster. https://getbootstrap.com/ https://www.w3schools.com/booTsTrap/ Bootstrap Features • HTML and CSS based design templates for grid (layout), typography, forms, buttons, tables, navigation, modals, image carousels and many other, as well as optional JavaScript plugins. HTML JavaScript • JavaScript (JS) makes HTML pages more dynamic and interactive. • Common uses include image manipulation, form validation, and dynamic changes of content. • Specifically, we will use JS to: • change/add/remove HTML elements • change HTML attributes • change HTML styles • react to (or create new) HTML events I am a dynamic gif! Please turn on the Slide Show mode Where to put • In HTML, JavaScript code must be inserted between <script> and </script> tags. • You can place any number of scripts in an HTML document. Scripts can be placed in the <body>, in the <head>, or in both. <script> function myFunction() { document.getElementById() is a document.getElementById("demo").innerHTML = "Paragraph changed."; useful function in JS, we will address it later.