Thuc Hanh - Basic HTML & PHP
Thuc Hanh - Basic HTML & PHP
1.1. HTML Elements ................................................................................................. 2 1.1.1. HTML Elements .......................................................................................... 2 1.1.2. HTML Element Syntax ............................................................................... 2 1.1.3. Nested HTML Elements.............................................................................. 2 1.1.4. HTML Document Example ......................................................................... 2 1.2. HTML Basic ....................................................................................................... 2 1.2.1. HTML Headings.......................................................................................... 2 1.2.2. HTML Paragraphs ....................................................................................... 3 1.2.3. HTML Links................................................................................................ 4 1.2.4. HTML Images ............................................................................................. 4 1.3. HTML Attributes ................................................................................................ 4 1.3.1. HTML Attributes ......................................................................................... 4 1.3.2. Always Quote Attribute Values .................................................................. 4 1.3.3. HTML Tip: Use Lowercase Attributes ....................................................... 4 1.4. HTML Links....................................................................................................... 5 1.4.1. Hyperlinks, Anchors, and Links .................................................................. 5 1.4.2. An HTML Link ........................................................................................... 5 1.4.3. The href Attribute ........................................................................................ 5 1.4.4. The target Attribute ..................................................................................... 5 1.4.5. The name Attribute ...................................................................................... 6 1.5. HTML Tables ..................................................................................................... 6 1.5.1. Tables .......................................................................................................... 6 1.5.2. Tables and the Border Attribute .................................................................. 6 1.5.3. Headings in a Table ..................................................................................... 7 1.5.4. Empty Cells in a Table ................................................................................ 7 1.6. HTML Styles ...................................................................................................... 8 1.6.1. The HTML Style Attribute .......................................................................... 8 1.6.2. HTML Style Examples................................................................................ 8 1.6.3. Deprecated Tags and Attributes .................................................................. 9 1.7. HTML Lists ........................................................................................................ 9 1.7.1. Unordered Lists ........................................................................................... 9 1.7.2. Ordered Lists ............................................................................................. 10 1.7.3. Definition Lists .......................................................................................... 10 1.8. HTML Text Formatting.................................................................................... 10 1.8.1. HTML Formatting Tags ............................................................................ 10 1.8.2. Text Formatting Tags ................................................................................ 11 1.8.3. Citations, Quotations, and Definition Tags ............................................... 11 1.9. Exercises ........................................................................................................... 12 Exercise 1. Discover HTML ............................................................................... 12 Exercise 2. Identifier ........................................................................................... 12 Exercise 3. URI ................................................................................................... 13 Exercise 4. Run all PHP examples in the lesson ................................................. 13 Exercise 5. Your profile ...................................................................................... 13 REFERENCES ........................................................................................................ 13 1
* The start tag is often called the opening tag. The end tag is often called the closing tag.
An HTML element starts with a start tag / opening tag An HTML element ends with an end tag / closing tag The element content is everything between the start and the end tag Some HTML elements have empty content Empty elements are closed in the start tag Most HTML elements can have attributes
Example
<h1>This is a heading</h1> <h2>This is a heading</h2> <h3>This is a heading</h3>
Use HTML headings for headings only. Don't use headings to make text BIG or bold. Search engines use your headings to index the structure and content of your web pages. Since users may skim your pages by its headings, it is important to use headings to show the document structure. H1 headings should be used as main headings, followed by H2 headings, then less important H3 headings, and so on.
Example
<p>This is a paragraph</p> <hr /> <p>This is a paragraph</p> <hr /> <p>This is a paragraph</p>
* HTML Comments
Comments can be inserted in the HTML code to make it more readable and understandable. Comments are ignored by the browser and are not displayed. Comments are written like this:
Example
<!-- This is a comment -->
Example
<p>This is a paragraph</p> <p>This is another paragraph</p>
Example
<p>This is a paragraph <p>This is another paragraph The example above will work in most browsers, but don't rely on it. Forgetting the end tag can produce unexpected results or errors.
Use the <br /> tag if you want a line break (a new line) without starting a new paragraph:
Example
<p>This is<br />a para<br />graph with line breaks</p> The <br /> element is an empty HTML element. It has no end tag.
Example
<a href="http://www.w3schools.com">This is a link</a>
Example
<img src="w3schools.jpg" width="104" height="142" />
HTML elements can have attributes Attributes provide additional information about the element Attributes are always specified in the start tag Attributes come in name/value pairs like: name="value"
Attribute Example
HTML links are defined with the <a> tag. The link address is provided as an attribute:
Example
<a href="http://www.w3schools.com">This is a link</a>
However, the World Wide Web Consortium (W3C) recommends lowercase attributes/attribute values in their HTML 4 recommendation Newer versions of (X)HTML will demand lowercase attributes.
Example
<a href="http://www.w3schools.com/" target="_blank">Visit W3Schools!</a>
To display a table with borders, you will have to use the border attribute: <table border="1"> <tr> <td>Row 1, cell 1</td> <td>Row 1, cell 2</td> </tr> </table>
row 2, cell 1 Note that the borders around the empty table cell are missing (NB! Mozilla Firefox displays the border). To avoid this, add a non-breaking space ( ) to empty data cells, to make the borders visible: <table border="1"> <tr> <td>row 1, cell 1</td> <td>row 1, cell 2</td> </tr> <tr> <td>row 2, cell 1</td> <td> </td> </tr> </table> How it looks in a browser: row 1, cell 1 row 1, cell 2 row 2, cell 1
This text is in Times and green</p> <p style="font-size:30px">This text is 30 pixels high</p> </body> </html>
Coffee Milk
Inside a list item you can put paragraphs, line breaks, images, links, other lists, etc.
10
11
<blockquote> Here is a long quotation here is a long quotation here is a long quotation here is a long quotation here is a long quotation here is a long quotation here is a long quotation here is a long quotation here is a long quotation. </blockquote>
1.9. Exercises
Exercise 1. Discover HTML
- Create a simple HTML page as this below webpage: <html> <body> <h1 style="text-align:center">This is a HTML practice exercise</h1> <hr /> <p>The heading above is aligned to the center of this page. The heading above is aligned to the center of this page. The heading above is aligned to the center of this page.</p> <hr /> <p> This paragraph contains a lot of lines in the source code, but the browser ignores it. </p> <hr /> <p> This paragraph contains a lot of spaces in the source code, but the browser ignores it. </p> <hr /> <h5>This is heading 5</h5> <hr /> <h6>This is heading 6</h6> </body> </html> - You should modify each tag by yourself and watch the effect of that modification.
Exercise 2. Identifier
- Create identifiers.html file to add explanations and examples of identifiers - Put it into the htdocs directory on Zend\ Apache2 to publish it - Browse this file
Exercise 3. URI
- Check what sort of URI schemes exist - Create hyperlinks for some of them into your html file (named uris.html) - Try to browse these hyperlinks
Exercise 4. Run all PHP examples in the lesson
- Create a simple HTML page as your personal webpage - The profile should include: + Paragraph, text + Images and hyperlinks + Table for layout + many HTML elements as possible (which you have learned). - Below are the suggested layout: Personal Details Image
Education process Working process Society activities Skills Experiences Certifications Hobbies Desire
REFERENCES
[1] http://www.w3schools.com/html
13