Lecture 8 MoreCSSexamplesAndHTML5
Lecture 8 MoreCSSexamplesAndHTML5
http://www.cs.nott.ac.uk/~bnk/WPS/border.html
Margins
● The space between the border of an element
and its neighbor element
● The margins around an element can be set
with margin-left, etc. - just assign them a
length value
<img src = "c210.jpg" style = "float:
right; margin-left: 0.35in; margin-
bottom: 0.35in" />
Padding
● The distance between the content of an
element and its border
• Controlled by padding, padding-left, etc.
http://www.cs.nott.ac.uk/~bnk/WPS/marpads.html
Page Layout
• By default, webpage content flows as a
single column.
• Each block - heading, list, paragraph etc.
appears one after the other.
• Most websites implement more complex
page layouts.
• Page contents arranged into columns
• Header and footer sections
A Typical Website Layout
Header
Navigation Page Content Additional
Bar Links
Footer
<div id="footer">Footer</div>
Footer width:974px
The float Property
Header width:974px
Footer
Header
Navigation Page Content Additional
Bar Links
Footer
http://www.cs.nott.ac.uk/~bnk/WPS/twocolumn.
html
New HTML 5 Semantic
Elements
• HTML 5 features new elements we can
use instead of the <div>.
• <header>
• <article>
• <footer>
• <aside>
• Add greater meaning than <div>
elements with id attributes.
HTML5 new features
● The video and audio elements for media
playback
● The canvas element for drawing
● New content specific elements, e.g:
• article, footer, header, nav, section
● New form controls, e.g.:
• calendar, date, time, email, url, search
● Better support for local offline storage
HTML5 Video
● Until now, there has never been a standard for
showing video on a web page
● Most videos are shown through a plugin (like flash)
• However, not all browsers have the same plugins
● HTML5 specifies a standard way to include video,
with the video element
<video src="movie.ogg“
controls="controls">
</video>
http://www.cs.nott.ac.uk/~bnk/WPS/video.html
Video Formats
Format IE Firefox Opera Chrome Safari
Ogg No 3.5+ 10.5+ 5.0+ No
MPEG 4 No No No 5.0+ 3.0+
WebM No No 10.6+ 6.0+ No
• Ogg = Ogg files with Theora video codec and Vorbis audio
codec
• MPEG4 = MPEG 4 files with H.264 video codec and AAC
audio codec
• WebM = WebM files with VP8 video codec and Vorbis
audio codec
HTML5 Audio
● So far no standard for playing audio on web page
● Most audio are played through a plugin (flash)
• However, not all browsers have the same plugins
● HTML5 specifies a standard way to include audio,
with the audio element
● The audio element can play sound files, or an
audio stream
<audio src="song.ogg" controls="controls">
Your browser does not support the audio
element.
</audio>
Audio Formats
Firefox Opera Chrome
Format IE 8 Safari 3.0
3.5 10.5 3.0
Ogg
No Yes Yes Yes No
Vorbis
MP3 No No No Yes Yes
Wav No Yes Yes No Yes
Canvas Element
● Uses JavaScript to draw graphics on a web page
● A rectangular area, you control every pixel of it
● It has several methods for drawing paths, boxes,
circles, characters, and adding images
● Create a Canvas element
• Add a canvas element to the HTML5 page.
• Specify the id, width, and height of the element
<canvas id="myCanvas" width="200"
height="100"></canvas>
Canvas Element
● Draw with JavaScript:
<script type="text/javascript">
var c=document.getElementById("myCanvas");
var cxt=c.getContext("2d");
cxt.fillStyle="#FF0000";
cxt.fillRect(0,0,150,75);
</script>
http://www.cs.nott.ac.uk/~bnk/WPS/canvas.html
Canvas Element – line example
Opera has the best support for the new input types. However, you can
already start using them in all major browsers. If they are not
supported, they will behave as regular text fields.
HTML5 Web Storage
● Two new objects for storing data on the client:
• localStorage - stores data with no time limit
• sessionStorage - stores data for one session
● So far this done with cookies
• But not suitable for large amounts of data, because they
are passed on by every request to the server
● In HTML5, the data is used only when asked for
• It is possible to store large amounts of data without
affecting the website's performance
● Data is stored in different areas for different websites,
and a website can only access data stored by itself
● HTML5 uses JavaScript to store and access the data
Browser Support
● HTML5 is not yet an official standard, and no
browser has full HTML5 support
● Canvas support - Firefox 3.0+, Safari 3.0+,
Chrome 3.0+, Opera 10.0+
● HTML5 Storage support – IE8+, Firefox 3.5+,
Safari 4.0+, Chrome 4.0+, Opera 10.5+
● Upcoming Internet Explorer 9 will be supporting
most HTML5 features
Page Layout and Mobile
Devices
• Columned designs do not suit mobile
devices.
• Screen width
• Even flexible designs have limits at low
resolutions.
• The handheld media type has limited
support.
• One solution is CSS3 Media Queries.
CSS3 Media Queries
<link href="style.css" rel="stylesheet" type="text/css"/>