Bài giảng Web Technologies and e-Services - Bài 2: HTML

vHTML 5 specify DOCTYPE as follows: vNew tags introduced in HTML5 for better structure § header − This tag represents the header of a section. § footer − This tag represents a footer for a section and can contain information about the author, copyright information, etc. § nav − This tag represents a section of the document intended for navigation. § dialog − This tag can be used to mark up a conversation. § figure − This tag can be used to associate a caption together with some embedded content, such as a graphic or video. § section − This tag represents a generic document or application section. It can be used together with h1-h6 to indicate the document structure. § article − This tag represents an independent piece of content of a document, such as a blog entry or newspaper article. § aside − This tag represents a piece of content that is only slightly related to the rest of the page.

pdf45 trang | Chia sẻ: hachi492 | Ngày: 06/01/2022 | Lượt xem: 415 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu Bài giảng Web Technologies and e-Services - Bài 2: HTML, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
IT4409: Web Technologies and e-Services Lec 2: HTML 1 Objectives v Describe hypertext and HTML standards v Understand HTML elements and markup tags v Create the basic structure of an HTML file v Insert an HTML comment v Work with block-level elements v Create lists, tables, hyperlinks and insert images v Learn HTML5 tags v Work with forms and inputs 2 Outline 1. Basic HTML § hypertext § tags & elements § text formatting § lists, hyperlinks, images § tables, frames 2. Advanced HTML 3 Hypertext & HTML • HyperText Markup Language (HTML) is the language for specifying the static content of Web pages (based on SGML, the Standard Generalized Markup Language) § hypertext refers to the fact that Web pages are more than just text • can contain multimedia, provide links for jumping within the same document & to other documents § markup refers to the fact that it works by augmenting text with special symbols (tags) that identify the document structure and content type Hypertext & HTML (cont.) 5 • HTML is an evolving standard (as new technology/tools are added) § HTML 1 (Berners-Lee, 1989): very basic, limited integration of multimedia in 1993, Mosaic added many new features (e.g., integrated images) § HTML 2.0 (IETF, 1994): tried to standardize these & other features, but late in 1994-96, Netscape & IE added many new, divergent features § HTML 3.2 (W3C, 1996): attempted to unify into a single standard but didn't address newer technologies like Java applets & streaming video § HTML 4.0 (W3C, 1997): current standard (but moving towards XHTML) attempted to map out future directions for HTML, not just react to vendors § XHTML 1.0 (W3C, 2000): HTML 4.01 modified to conform to XML standards § XHTML 1.1 (W3C, 2001): “Modularization” of XHTML 1.0 § HTML 5 (Web Hypertext Application Technology Working Group, W3C, 2006): New version of HTML4, XHTML 1.0, and DOM 2 (still a work in progress), no longer based on SGML, but “backward compatible” with parsing of older versions of HTML Web Development Tools • Many high-level tools exist for creating Web pages e.g., Microsoft FrontPage, Netscape Composer, Adobe PageMill, Macromedia DreamWeaver, HotDog, also, many applications have "save to HTML" options (e.g., Word) Don’t use these tools!! for most users who want to develop basic, static Web pages, these are fine (but many of these programs produce very poorly structured HTML code) why are we learning low-level HTML using a basic text editor? § may want low-level control § may care about size/readability of pages § may want to “steal" components from other pages and integrate into existing pages § may want dynamic features such as scripts or applets § remote editing of web pages may only be possible using a basic text editor § sticking to (internationally and industrially) agreed upon standards will help ensure your web documents are rendered as you intend them to look and operate as you desire 6 Tags and Elements • HTML specifies a set of tags that identify structure of the document and the content type § tags are enclosed in • specifies an image § most tags come in pairs, marking a beginning and ending • and enclose the title of a page • An HTML element is an object enclosed by a pair (in most cases) of tags § My Home Page is a TITLE element § This text appears bold. is a BOLD element § Part of this text is bold. is a PARAGRAPH element that contains a BOLD element An HTML document is a collection of elements (text/media with context). 7 Structural Elements • an HTML document has two main structural elements § HEAD contains setup information for the browser & the Web page • e.g., the title for the browser window, style definitions, JavaScript code, § BODY contains the actual content to be displayed in the Web page <!–- Version information -- -- File: page01.html -- -- Author: CS443-- -- Creation: 22.09.09 -- -- Description: introductory page -- -- Copyright: U.Liverpool -- --> My first HTML document Hello world! HTML documents begin and end with and tags Comments appear between HEAD section enclosed between and tags BODY section enclosed between and * Find more info on HTML docs! view page 8 and elements 9 § The element is where you include a element (that appears in the title bar of the browser). § You can also include lots of other type of information in the element. o Cascading Style sheet information, or a link to an external style sheet (or several) o “Meta” data, such as who authored the page, the type of content, and clues that search engines may (or may not) use to help categorize your page o JavaScript code § The element contains the main bulk of the material to be displayed on the webpage. o Paragraphs o Tables and lists o Images o JavaScript code o PHP code can be included here too (if passed through a PHP parser before being served to the client’s browser) o Other embedded objects Text Layout vfor the most part, layout of the text is left to the browser § (almost) every sequence of whitespace is interpreted as a single space § browser automatically wraps the text to fit the window size vcan override some text layout § can specify a new paragraph (starts on a new line, preceded by a blank line) using § can cause a line break using the tag (“self- closing” tag) § can force a space character using the symbol for a “non-breaking space”:   Text Layout This is a paragraph of text made up of two lines. This is another paragraph with a   GAP   between some of the words.    This paragraph is indented on the first line but not on subsequent lines. view page 10 Separating Blocks of Text vcan specify headings for paragraphs or blocks of text § tags produce a large, bold heading § tags produce a slightly smaller heading . . . § tags produce a tiny heading vcan insert a horizontal rule to divide sections § draws line across window Blocks of Text Major heading 1 Here is some text. Subheading Here is some subtext. Major heading 2 Here is some more text. view page 11 The Basic Web page – A Worked Example Bill Smiggins Inc. Bill Smiggins Inc. About our Company... This Web site provides clients, customers, interested parties and our staff with all of the information that they could want on our products, services, success and failures. Products We are probably the largest supplier of custom widgets, thingummybobs, and bits and pieces in North America. view page 12 Text Appearance vcan specify styles for fonts § specify bold § specify italics § specify typewriter-like (fixed-width) font § increase the size of the font § decrease the size of the font § put emphasis § put even more emphasis § specify a subscript § a superscript § include ready- formatted text § & &al; > " © escape characters used in HTML control § Find more info on text tags! Text Variations and Escape Sequences Text Variations We can use simple tags to change the appearance of text within Web pages. Even superscript and subscripts are supported. Text Escape Sequences & < > " © Preformatted text University of Liverpool Department of Computer Science Ashton Building, Ashton Street Liverpool, L69 3BX, UK view page 13 Lists vthere are 3 different types of list elements § specifies an ordered list (using numbers or letters to label each list item) • identifies each list item •can set type of ordering, start index § specifies unordered list (using a bullet for each) • identifies each list item § specifies a definition list • identifies each term • identifies its definition * We will learn more about the “style” attributes soon enough. (Sort of) Simple Lists .my_li:before { content: counter(list) ": "; counter-increment: list; } ... first list item... ... second list item... ... Dweeb young excitable person who may mature into a Nerd Hacker a clever programmer Nerd technically bright but socially inept person <ol style="list-style-type: none; counter-reset: list 29;" > Makes first item number 30. Next item continues to number 31. view page 14 Hyperlinks vperhaps the most important HTML element is the hyperlink, or ANCHOR § •where URL is the Web address of the page to be displayed when the user clicks on the link •if the page is accessed over the Web, must start with http:// •if not there, the browser will assume it is the name of a local file § <a href="URL" target="_blank"> •causes the page to be loaded in a new Window * Find more info on attribute TARGET Hyperlinks The University of Liverpool <a href="page07.html" target="_blank"> Open page07 in a new window view page 15 Hyperlinks (cont.) vfor long documents, you can even have links to other locations in that same document § •where ident is a variable for identifying this location, where "xxxx" can, in principle, be any HTML element •(this is actually an HTML5 language specification, but seems to work in most browsers) § •will then jump to that location within the file § •can jump into the middle of another file just as easily Internal Links in a Page [ HTML | HTTP | IP | TCP ] Computer acronyms: HTML HyperText Markup Language HTTP HyperText Transfer Protocol IP Internet Protocol TCP Transfer Control Protocol view page 16 Images vcan include images using img § by default, browsers can display GIF and JPEG files, more modern browsers can also typically support PNG files and SVG graphics (of course, use at your own risk) § other image formats may require plug-in applications for display •<img src="URL (or filename)" height="n" width="n" alt="text" title= "text" /> •again, if file is to be accessed over the Web, must start with http:// (if not, will assume local file) • Find more info on Image example <img src="" title="Liverpool's Anglican cathedral" alt="image of Liverpool's Anglican Cathedral" width="400" /> The Anglican Cathedral of Liverpool view page 17 Images (cont.) 18 § src - specifies the file name (and can include a URL) § width and/or height - dimensions in pixels (often only need to specify one of them and the other is automatically scaled to match, where possible pictures should be resized using other programs to save on bandwidth and problems that some (older) browsers might have with resizing images) § title - displayed when the mouse is “hovered” over the picture § alt - text that is displayed when the image is missing, can’t be loaded (e.g. if file permissions aren’t set correctly), or if the client has disabled loading images in his/her browser Tables • tables are common tools for arranging complex layout on a Web page § a table divides contents into rows and columns § by default, column entries are left-justified, so you must provide for your own alignment when needed (using Cascading Style Sheets, for example) Tables A Simple Table Left Column Right Column Some data Some other data specify a table element specify a row in the table specify table data (i.e., each column entry in the table) view page 19 Layout in a Table vcan have a border on tables using the “style” attribute <table style= "border: 1px solid;"> increasing the number makes the border thicker vcan control the horizontal & vertical layout within cells vcan apply layout to an entire row We will explore this more with Cascading Style Sheets (CSS). Table Layout LeftColumn <td style="border: 1px solid; vertical-align: top;"> Right Column Some data Some data view page 20 Table Width vby default, the table is sized to fit the data vcan override & specify the width of a table relative to the page For example <table style="width: 60%"> Table Width left-most right-most view page 21 Other Table Attributes vcan control the space between cells & margins within cells This is the “padding” attribute in the table and th,td style sheet declarations (more on this with Cascading Style Sheets). vcan add headings is similar to but displays heading centered in bold vcan have data that spans more than one column vsimilarly, can span more than one row (This example uses CSS style sheet commands in the page .) Table Formatting table { border: 1px solid; padding: 1px;} th, td { border: 1px solid; padding: 10px; text-align: center; } HEAD1 HEAD2 HEAD3 one two three four five six seven view page 22 Frames • Frames provide the ability to split the screen into independent parts v Frames are going out of fashion, partly because they interact poorly with web search engines (i.e. search engines cannot generally access the data stored in the inset frame objects). v Frames can also “break” the regular behaviour of browsers, most notably the “Back” button on the browser can behave in unexpected ways. v Because of these drawbacks to frames, I will not be discussing them in this course. v If you wish to design websites using frames (why would you??), I would encourage you to use the XHTML XFrames specifications (see the W3C website for more details), but this specification isn’t fully supported by all browsers at this time. v Frames are also not supported by the HTML 5 specification. 23 Content vs. Presentation • Most HTML tags define content type, independent of presentation. § exceptions? (e.g. for bold text and .. for italicized text) • Style sheets associate presentation formats with HTML elements. § CSS1: developed in 1996 by W3C § CSS2: released in 1998, but still not fully supported by all browsers § CSS3: specification still under development by the W3C, “completely backwards compatible with CSS2” (according to the W3C) • The trend has been towards an increasing separation of the content of webpages from the presentation of them. • Style sheets allow us to maintain this separation, which allows for easier maintenance of webpages, and for a consistent look across a collection of webpages. 24 Content vs. Presentation (cont.) vStyle sheets can be used to specify how tables should be rendered, how lists should be presented, what colors should be used on the webpage, what fonts should be used and how big/small they are, etc. vHTML style sheets are known as Cascading Style Sheets, since can be defined at three different levels 1.inline style sheets apply to the content of a single HTML element 2.document style sheets apply to the whole BODY of a document 3.external style sheets can be linked and applied to numerous documents, might also specify how things should be presented on screen or in print lower-level style sheets can override higher-level style sheets vUser-defined style sheets can also be used to override the specifications of the webpage designer. These might be used, say, to make text larger (e.g. for visually-impaired users). 25 Inline Style Sheets vUsing the style attribute, you can specify presentation style for a single HTML element § within tag, list sequence of property:value pairs separated by semi-colons font-family:Courier,monospace font-style:italic font-weight:bold font-size:12pt font-size:large font-size:larger color:red color:#000080 background-color:white text-decoration:underline text-decoration:none text-align:left text-align:center text-align:right text-align:justify vertical-align:top vertical-align:middle vertical-align:bottom text-indent:5em text-indent:0.2in Inline Style Sheets <p style="font-family:Arial,sans- serif; text-align:right">This is a right-justified paragraph in a sans serif font (preferably Arial), with some green text. And <a style="color:red; text-decoration:none; font-size:larger;" href="page01.html">here is a formatted link. view page 26 Inline Style Sheets (cont.) vmore style properties & values margin-left:0.1in margin-right:5% margin:3em padding-top:0.1in padding- bottom:5% padding:3em border-width:thin border-width:thick border-width:5 border-color:red border-style:dashed border-style:dotted border-style:double border-style:none whitespace:pre list-style-type:square list-style-type:decimal list-style-type:lower-alpha list-style-type:upper-roman Inline Style Sheets Here is an image <img src="VictoriaBldg.jpeg" alt="image of Victoria Building" style="margin-left:0.3in; margin-right:0.3in; vertical-align:middle; border-style:double; border-color:blue" /> embedded in text. one thing or another <ul style="list-style-type:square; whitespace:pre"> with this or that view page 27 Inline Style Sheets (cont.) vstyle sheets can be applied to tables for interesting effects Inline Style Sheets <caption style="color:red; font-style:italic; text-decoration:underline"> Student data. name age Chris Smith 19 Pat Jones 20 Doogie Howser 9 view page 28 Document Style Sheets • Inline style sheets apply to individual elements in the page. § using inline style directives can lead to inconsistencies, as similar elements are formatted differently • e.g., we might like for all elements to be centered § inline definitions mix content & presentation è violates the general philosophy of HTML • As a general rule, inline style sheet directives should be used as sparingly as pos • Alternatively, document style sheets allow for a cleaner separation of content and presentation. § style definitions are placed in the of the page (within STYLE tags) § can apply to all elements, or a subclass of elements, throughout the page sible. 29 Document Style Sheets vdocument style sheets ensure that similar elements are formatted similarly § can even define subclasses of elements and specify formatting p.indented defines subclass of paragraphs • inherits all defaults of • adds new features to specify this newly defined class, place class="ID" attribute in tag vnote how "clean" the element is Document Style Sheets h1 {color:blue; text-align:center} p.indented {text-indent:0.2in} Centered Title This paragraph will have the first line indented, but subsequent lines will be flush. This paragraph will not be indented. The End view page 30 Document Style Sheets (cont.) vdocument style sheets are especially useful in formatting tables veffectively separates content from presentation v what if you wanted to right- justify the column of numbers? v what if you changed your mind? Inline Style Sheets table {font-family:Arial,sans-serif} caption {color:red; font-style:italic; text-decoration:underline} th {background-color:red} Student data. name age Chris Smith 19 Pat Jones 20 Doogie Howser 9 view page 31 Pseudo-Elements vpseudo-elements are used to address sub-parts of elements § can specify appearance of link in various states •:visited :active :hover § can specify format of first line in page or paragraph •:first-line § can specify format of first letter in page or paragraph •:first-letter vDanger : changing the look of familiar elements is confusing vCareful : current browsers do not support all CSS2 features Title for Page a {color : red; text-decoration : none; font-size : larger} a:visited {color : black} a:active {color : orange} a:hover {color : blue} p:first-letter {font-size : large; color : white; background-color : darkblue} Welcome to my Web page. I am so happy you are here. Be sure to visit CNN for late-breaking news. view page 32 External Style Sheets • modularity is key to the development and reuse of software § design/implement/test useful routines and classes § package and make available for reuse § saves in development cost & time § central libraries make it possible to make a single change and propagate the changes • external style sheets place the style definitions in separate files § multiple pages can link to the same style sheet, consistent look across a site § possible to make a single change and propagate automatically § represents the ultimate in content/representation separation 33 Modularity & Style Sheets vIdeally, the developer(s) of a Web site would place all formatting options in an external style sheet. vAll Web pages link to that same style sheet for a uniform look. § simplifies Web pages since only need to specify structure/content tags § Note: no tags are used in the external style sheet Title for Page <link rel="stylesheet" type="text/css" href="myStyle.css" title="myStyle“ /> Centered Title This paragraph will have the first line indented, but subsequent lines will be flush. This paragraph will not be indented. The End /* myStyle.css CS443 02.09.05 */ h1 {color : blue; text-align : center} p.indented {text-indent:0.2in} view page 34 and Tags • Problem: font properties apply to whole elements, which are often too large § Solution: a new tag to define an element in the content of a larger element - § The default meaning of is to leave the content as it is (i.e. unchanged) .bigred {font-size: 24pt; font-family: Ariel; color: red} ... ... Now is the best time ever! Now is the best time ever! § Another tag that is useful for style specifications: Used to create document sections (or divisions) for which style can be specified e.g., a section of five paragraphs for which you want some particular style • Use to apply a document style sheet definition to its content § The tag is similar to other HTML tags, they can be nested and they have id and class attributes view page 35 Web rules of thumb (ok, my rules of thumb) • HTML and CSS provide lots of neat features, but just because you can add a feature doesn't mean you should! don't add features that distract from the content of the page Ø use color & fonts sparingly and be careful how elements fit together e.g, no purple text on a pink background, no weird fonts e.g. I find bright white text on a black background difficult to read Consider the needs of visually impaired users of your website!! Ø use images only where appropriate e.g., bright background images can make text hard to read e.g., the use of clickable images instead of standard HTML buttons or links can slow access Ø don't rely on window or font size for layout e.g., font size may be adjusted by viewer, window constrained Ø don’t be annoying e.g., lots of pop-up windows, excessive advertising, silly music Ø break a large document into several smaller ones or provide a menu for navigation Ø stick to standard features and test as many browsers as possible (and versions of the same browser) Ø utilize style sheets to make changes easy & ensure consistency 36 Outline 1. Basic HTML 2. Advanced HTML § HTML5 tags and attributes § forms & inputs 37 HTML5 Tags v HTML5 has lots of flexibility: • Uppercase tag names • Quotes are optional for attributes • Attribute values are optional • Closing empty elements are optional v HTML5 tag names are case insensitive • convention is to use all lower case v HTML added support for multimedia HTML5 Attributes v Elements may contain attributes § used to set various properties of an element. v Some attributes are defined globally and can be used on any element, others are defined for specific elements only. v All attributes have a name and a value v Attributes defined in CSS v Attributes may only be specified within start tags and must never be used in end tags. § attributes are case insensitive § convention is to stick with lower case. HTML5 New Tags vHTML 5 specify DOCTYPE as follows: vspecify Character Encoding as follows: vNew tags introduced in HTML5 for better structure § header − This tag represents the header of a section. § footer − This tag represents a footer for a section and can contain information about the author, copyright information, etc. § nav − This tag represents a section of the document intended for navigation. § dialog − This tag can be used to mark up a conversation. § figure − This tag can be used to associate a caption together with some embedded content, such as a graphic or video. ... ... ... ... ... 40 HTML5 New Tags § section − This tag represents a generic document or application section. It can be used together with h1-h6 to indicate the document structure. § article − This tag represents an independent piece of content of a document, such as a blog entry or newspaper article. § aside − This tag represents a piece of content that is only slightly related to the rest of the page. 41 Header Navigation Aside Footer Section Article Footer Article Footer Article Footer HTML5 New Tags v HTML5 offers new elements for media content: 42 Not supported. <video src="video.ogv" controls poster="poster.jpg" width="320" height="240"> Download movie HTML5 New Tags v element: 43 function draw() { var ctx = document.getElementById('canvas').getContext('2d'); var img = new Image(); img.onload = function(){ ctx.drawImage(img,0,0); ctx.beginPath(); ctx.moveTo(30,96); ctx.lineTo(70,66); ctx.lineTo(103,76); ctx.lineTo(170,15); ctx.stroke(); } img.src = 'images/backdrop.png'; } HTML5 New Tags v New input elements: 44 button checkbox color date datetime datetime-local email file hidden image month number password radio range reset search submit tel text time url week Thank you for your attentions! 45

Các file đính kèm theo tài liệu này:

  • pdfbai_giang_web_technologies_and_e_services_bai_2_html.pdf