210 likes | 308 Vues
Learn the fundamentals of HTML for website building, including tags, attributes, linking pages, and using style sheets effectively. Understand the importance of site layout strategies and the relevance of forms in web development.
E N D
Making Database backed Websites Session 1 Building a simple website by hand
How does the web work? • A web-server waits for requests from a browser (web-client) • When you go to a site your browser sends a request to the web server • It sends back the HTML for the page • Your browser parses the page looking for other resources it needs (eg images) • It requests and receives the additional resources
HTML • Originally designed as a SemanticMarkup Language • Consists of Head and Body • Head contains information about the web page (eg title) • Body contains the content of the page itself
Tags • HTML tags markup parts of the page as being head, body, a title, bold, etc. • Tags look like… • <head> ...some stuff… </head> • Some tags also have attributes • <img src=“foo.gif”> • Note, in HTML not all tags close
A short page • <html> • <head> • <title>A short page</title> • </head> • <body> • Some content for our short page • </body> • </html> • Note: The indenting is not important, but it makes it easier to see the structure of the document.
The major tags • <HTML> • <head> • <title> • <body> • <h1> <h2> <h3> <h4> <h5> <h6> • <p> <img src=“foo.gif” alt=“a foo”> • <table> • <tr> • <td> <th> • <a href=“foo.html”> <a name=“bar”> • <!-- comment -->
Linking pages together • <html> • <body> • <ul> • <li><a href=“stuff.html”>Stuff</a></li> • <li><a href=“bother.html”>Bother</a></li> • </ul> • </body> • </html> • This page will be have links to a page called stuff.html and another called bother.html
Blue Peter moment • Here’s one I prepared earlier… • Errr…why does it look awful? We need some style!
Getting it to look good • There are two broad approaches… • Using HTML as a layout language (a Bad Thing) • …or… • Using Semantic Markup (a Good Thing)
Non-Semantic Markup • <b> <i> • <font> • <table> when used for layout • Widely used (even by me), but considered a “Bad Thing”. Don’t do it…use semantic markup instead
Semantic Markup • Use markup to denote the meaning of parts of the document. • i.e. Which part is the title, which parts are headings • Then use stylesheets to control the appearance. • <strong> <em> <span> <div>
Style Sheets • h1 { • font-family: Helvetica; • color: #008800; • background-color: #ffffff; • text-decoration: underline; • } • div.special { color: #bbbbbb; }
Style Sheets • Inline styles – the <style> tag • <style> • h1 { color: #ff0000; } • <style> • External Style sheets <link> tag • <link rel=“stylesheet” type=“text/css” href=“/styles/style.css”> • External styles generally are generally better, unless you want to add one extra style to a specific page, that’s never going to be used elsewhere… Why?
Colours • Look like #ff6790 (which is a pinkish colour) • Made up of Red, Green and Blue • #RRGGBB • Unfortunately in hexadecimal, (base 16).
Regions • <div class=“special”> • here’s some text in a grey region • </div> • <span class=“weird”>Freaky</span> • The appearance of the regions is defined by style sheets.
Site layout strategies • Addressing types • Absolute <a href=http://www.foo.com/bar.html> • will work from anywhere. The only option for linking to pages on another site • Relative <a href=“bar.html”> • assuming that the page with the link is in the same directory. Will stop working if you move either of the pages. • RootRelative <a href=“/bar.html”> • assuming the page with the link is on the same server. Will work so long as the target page is not moved. • Since sites tend to have lots of links within the site Root Relative is very useful.
Site layout strategies • Use folders to group related pages within a site. The URL can be a useful navigation tool for experienced surfers. • Put images that are used all over the site in one place – often in /images/ • Site wide style sheets in one place – say /styles/ • Resources that are only used for part of a site in subfolders.
Why does site layout matter? • If you’ve written 5 webpages, it probably doesn’t. • If you’ve written 5000 and you decide you want to change something… bad layout will toast you. • Bad separation of style from content will also toast you since you’ll have to update the style elements on every page.
Forms! • This is where it gets exciting… • <form action=“dosomething.php” method=“get”> • <input type=“button” name=“foo” value=“bar”> • <input type=“text” name=“baz” value=“wibble” size=“20”> • <input type=“checkbox” name=“c1” value=“c1on”> • <textarea rows=“6” cols=“40”> • Some text • </textarea> • </form>
So where does the data go? • We’ll come to that in the final week!! • For now just use the script “echo.php”
Questions? Presentation online at… http://people.surfaceeffect.com/pete/ tech/howitworks/dbwebsites/