Html5 and Ccs3
Html5 and Ccs3
HTML5
NE
& CSS3
The Complete Manual
The essential handbook for web designers
Welcome to
HTML5
& CSS3 The Complete Manual
HTML5 & CSS3 were first implemented in 2012.
Since then, web design has excelled, becoming
an art form that almost seems like technical
wizardry. In fact, all of these sites has been created
using the written craft of HTML and CSS, with the
added help of Javascript and jQuery. In this book
we aim to take you from the early stages of web
design, all the way to adding responsive elements
to your website with the use of brilliant tools such
as Bootstrap and Foundation. In no time, you’ll be
creating web wizardry yourself, so let’s get started.
HTML5
& CSS3
The Complete Manual
Imagine Publishing Ltd
Richmond House
33 Richmond Hill
Bournemouth
Dorset BH2 6EZ
+44 (0) 1202 586200
Website: www.imagine-publishing.co.uk
Twitter: @Books_Imagine
Facebook: www.facebook.com/ImagineBookazines
Publishing Director
Aaron Asadi
Head of Design
Ross Andrews
Production Editor
Jen Neal
Designer
Perry Wardell-Wicks
Photographer
James Sheppard
Printed by
William Gibbons, 26 Planetary Road, Willenhall, West Midlands, WV13 3XT
Distributed in Australia by
Network Services (a division of Bauer Media Group), Level 21 Civic Tower, 66-68 Goulburn Street, Sydney, New South
Wales 2000, Australia, Tel +61 2 8667 5288
Disclaimer
The publisher cannot accept responsibility for any unsolicited material lost or damaged in the post. All text and layout is
the copyright of Imagine Publishing Ltd. Nothing in this bookazine may be reproduced in whole or part without the written
permission of the publisher. All copyrights are recognised and used specifically for the purpose of criticism and review.
Although the bookazine has endeavoured to ensure all information is correct at time of print, prices and availability
may change. This bookazine is fully independent and not affiliated in any way with the companies mentioned herein.
HTML5 & CSS3 The Complete Manual © 2014 Imagine Publishing Ltd
ISBN 9781910439418
Part of the
bookazine series
Contents
What you can find inside the bookazine
Style. CSS
50 Format images
using CSS
Edit where your images
sit on the page
6
Create
your ow
websiten
Responsive design
8
An introduction to HTML Introducing HTML
An introduction to HTML
HyperText Markup Language, more commonly know as HTML, is the basic
building block of the web. It provides the structure, content and connection
between pages, allowing web designers to create interactive experiences.
Easy to learn, it offers limitless possibilities…
The majority of web pages are made up of one or more files that
are downloaded to a computer, which in turn are interpreted by a
web browser and finally rendered out to screen. At its simplest, a
web page is a plain text file that contains special instructions about
what kind of content is contained within. These instructions are
written in HTML – the language used on the world wide web.
HTML, or HyperText Markup Language to give it the full name,
is the core building block of a web page. HTML is a markup-based,
human-readable language that’s designed to be simple to write,
and easy to understand. A markup language is one where bits
of data are literally marked as being of a particular type. So, for
example, a piece of data that you want to render as a paragraph
would be ‘marked up’ with a paragraph marker.
Marking up
Markers are referred to as tags, and they have less-than and greater-
than symbols around them. This paragraph would be marked
up with a <p> tag at the start to denote a paragraph, and a
matching </p> tag at the end to signify the end of the paragraph.
HTML offers many tags for marking up content, and browsers are
programmed to interpret these tags, formatting the contents of
each tag according to a set of preset rules. This allows the <strong>
tag to render text in bold, and the <em> (for emphasis) tag to
render in italics. One of the major benefits of this system of marking
up content is that it’s easy to read – you don’t need any special
software to either write or read HTML documents, as they’re just
plain text. This makes it easy to create a functioning web page using
nothing more complex than a text editor.
9
Introducing HTML An introduction to HTML
10
Above Find a domain name to create an identity for your blog
An introduction to HTML Introducing HTML
What is HTML5?
The first requirement of any WordPress installation is the packages from $20 a month (approx £15) but offers
need for web space. There are thousands of web hosting gigabytes of storage and 1TB network transfer rates.
companies who will happily supply space for a small Other reputable web hosts to consider are Fasthosts
fee. However, to determine what sort of web hosting (www.fasthosts.co.uk), 1&1 (www.1and1.co.uk) and
package is needed the user needs to decide how much Heart Internet (www.heartinternet.co.uk). Once a
web space is needed and how much traffic is expected. package has been bought and paid for the web host will
Users can get 200MB of web space and gigabytes of send all the details (username, passwords etc) needed to
traffic for a very small fee. But if more space is likely to be take control of the web space.
needed, ie a photo blog, go for more. Don’t worry too To host a WordPress blog at a desired URL, ie
much about traffic to start with. New sites are not likely mywebsite.co.uk, a domain name needs to be
to get huge amounts of traffic immediately and this can purchased. Try www.123-reg.co.uk, this offers .co.uk
be changed at a later date very quickly and easily. domain names from £2.99 a year and .com domain
A small UK company that provides cheap and efficient names from £9.99 a year. Another well-respected domain
hosting is Z-Host (www.z-host.co.uk). It provides name supplier is Easily (www.easily.co.uk).
packages from as little as £15 a year (100MB of web If the prospect of finding web space and getting a
space and 10GB of monthly traffic), perfect for first time domain name seems too much like hard work, there is
bloggers. Alternatively, choose 1GB of web space and the hosted option. Go to www.wordpress.com, click
40GB of monthly traffic for £60 a year. At the other end Sign Up Now and all that’s needed is an email address.
of the scale there is a popular choice with web designer This gives a new user a unique WordPress URL, ie
Media Temple (www.mediatemple.net). This offers myname.wordpress.com and hosts the account.
11
Introducing HTML An introduction to HTML
12
An introduction to HTML Introducing HTML
page. If it finds any files called in, the browser will send a message
back to the web server asking for those files. The final result you see
in your web browser window may be the result of more than 20
individual files, brought together by the web browser and rendered
as a single web page!
13
Introducing HTML An introduction to HTML
and make some decisions about what content to show. This might
be as simple as including your name at the top of the page when
you’re logged in, or as complex as a fully loaded e-commerce web
store, but all these ‘server-side languages’ output the same final
result – plain HTML. It’s important that the web works this way, as
every web browser only has to support one kind of page structural
language, which makes it easier for both web designers and
browser vendors, not to mention for users of the web who know
that all they need to access any website is a web browser and an
internet connection.
14
An introduction to HTML Introducing HTML
17
Introducing HTML HTML glossary
HTML glossary
We demystify the definition of the most popular HTML jargon
a canvas tag can be styled eg width, This will include elements that need
height, border, to make it fit better to be seen on every page and will
The a tag defines a hyperlink, which with the graphics that are placed typically have navigation and link to an
is used to link to another web page. upon your web page. about page and contact page
The <a> tag is typically coupled with
the href attribute which will include class form
the link’s destination. For example, <a
href=”about.html”>link text</a> The class attribute can be applied to The <form> tag is a container that will
the div tag eg ‘div class=’. This will have contain all the necessary elements
aside a unique name that is not in the HTML to create a form. This could be text
specification. Unlike the id option the fields, checkboxes, labels and submit
This is a tag that was introduced in class identifier can be applied to more buttons, your usual form garb.
HTML5 and refers to content that is an than one element.
aside to the main content. The content head
in the aside tag should be relevant to div
its surrounding content. This tag contains a host of information
The div tag is used to create blocks that is typically hidden from the user,
audio of content in a web page. These are but is important for the browser
known as block elements. The tag to read. It will include the page
The <audio> tag allows for the will be coupled with id eg ‘div id=’ to title, keywords, scripts and links to
inclusion of audio files which can be create a unique name which typically stylesheets. The head tag comes
read directly by the browser without reflects what the content block is eg immediately after the html tag and
the need for a plug-in. Between the leftcol for left column. before the body tag.
audio tags will be the source od the
audio and any related attributes footer header
body The footer is the part of a page that A web page is typically split into
typically sits at the bottom of a page. different parts including the header.
The body tag is where all the content
seen on screen is stored. It sits after the
head tag and between the html tag.
br
Br is short for break, or more
specifically line breaks. It is an empty
tag which means it isn’t a set of tags
just a single tag. It is used to split long
headlines or long sentences.
canvas
The <canvas> tag is a container where
the necessary code is placed to show
the graphics created by the code. The <above> The canvas tag is a container for dynamic graphics
18
HTML glossary Introducing HTML
The header is typically at the top of (ordered) tag and a set of li tags are
the page and includes elements that required for each item. If three items
will typically be seen on every page eg are needed in a list then three sets of
the site title, logo and navigation. For a li tags are needed. The text inside the
tutorial on how to create your header, each list item will be displayed on a
go to page 60. web page. It is important to close each
of the li tags.
html
nav
The html tag is the tag that defines a
HTML document. It is the tag that all A tag introduced in HTML5, nav
other tags live within. You will find a is a semantic tag that is short for
HTML tag at the beginning and end of navigation. These are used to store any
<above> The script tag is where code, or link to
a document navigation or menus that are typically the code source is placed
found at the top of a web page,
img usually within the header. tag
Img is short for image and defines p The term tag refers to all the elements
where an image will go in a web page. of the HTML specification. The HTML
The img tag is typically paired with src, This is the HTML tag for paragraph. language is made up of tags that
which shows the source of the image This works exactly as a paragraph are contained in a set of brackets
and alt. Alt text is what will show in the would in a book. The paragraph of eg <body>.
browser if the image is not available. text would be surrounded by an
opening and closing set of tags eg title
li <p></p>.
The title tag is stored inside the head
The li tag is sort for list. These are script tag and determines the title of the
found inside the ul (unordered) or ol page. This title will appear in the
Web pages often include code title bar or tab in a web browser. It
beyond HTML and CSS that add is important that the title is concise
dynamic elements. A simple example and informative as it will be read by
is Google Analytics code and other the user and search engines. Do not
code written in JavaScript. The code is include notes within the tag as this will
stored inside a set of <script> tags to also show in your title.
help identify the code.
ul
section
Lists are an integral part of web pages
The section tag was introduced in and there are several options for
HTML5 and is a generic section of a creating lists. ul is short for unordered
<above> The video tag is a placeholder for web page that will contain general list which means the list is bullet
adding video into a web apge content such as text and images. It can pointed by default. The alternative
have its own id (name) to help identify option is ol, ordered list, which adds
the section, and is able to have a CSS numbers or letters eg a,b,c
class added. It is often has a title as well.
video
table
The <video> tag is a set of tags,
Tables are made up of rows and which will contain any related video
columns and were used to create information. For example, a basic
page layouts before CSS became version would contain width and
popular. They are now used to show height attributes along with the
<above> The elements of a HTML form are
stored inside the <form> tags off tables of data. source of the video.
19
Introducing HTML Create a basic layout
Header tag
The header differs from the head, as it’s
contained within the body of the HTML
page, meaning it gets displayed in the
browser. The header usually contains
company insignia, navigation and
possibly an introductory image
Footer
The footer tag denotes an element
that usually goes at the bottom of
the content, and contains items such
as author, contact info, telephone
numbers etc
Div tag
A div is used to
group content
together, in this
case we use it
to display our
content and
sidebar. Divs can
be nested within
each other and
can have IDs and
classes applied to
them so they can
be identified
20
Create a basic layout Introducing HTML
Code a link
Adding in links to other pages is a key part of web design
While links may seem like a simple element to add to a webpage, they
are the key building blocks of the entire internet. Similar to pages within
a book, separate webpages within a website help to break up content
by topic or purpose. Then, by adding in a navigation bar, it means that
visitors will be able to quickly between content.
Links are also one of the most important elements that Google and other search engines use to find
and index your site. The kind of content that you link out to, and the kind of content contained within
sites that link to your pages, are vital in informing the search engine on how to categorise your site for its
search results.
This tutorial will take you through adding in links leading to other pages in your website, and how to
link out to other people’s sites. Once you have added some links, your site can start to function how it’s
intended to, with visitors being able to view all the content contained with ease.
Unordered list Nested lists <ol> tag in place of the <ul>. This will
then replace the bullet points with
add in an unordered list you use the <ul>, and then list items can be added
<ul> tag. to that too. They will then be indented
Definition lists
again within that <ul>.
Add list items 001
002
<ul>
<li> Tea </li>
05 There is one other type of list
in HTML – the definition list.
It’s quite rarely used but allows an
003 <ul>
23
Introducing HTML All about div tags
An HTML page is made up of a series of tags which tell the web browser what to display and where.
The main building block of a page is a div tag, short for division. If you look at a newspaper page, you
will see that text is grouped together in columns. Images with captions are also together with a margin
around them. A div in HTML is similar to this, and it’s usual to group together content in a similar way.
While HTML5 has added a few new tags with more semantic names such as ‘header’ and ‘footer’, the
main body of most pages is still constructed using divs.
There is no limit on how many divs you have within a page and most webpages you visit online will
contain many, all nested within each other. Divs can contain text, images, video and audio, as well as
other HTML elements such as articles and sections.
This tutorial will show you how to make your first divs and then how to apply an ID or class to them
so when you’re ready you can apply CSS styles, or use JavaScript on them. We’ll be using plenty of them
throughout the book, and they are really simple. Don’t forget to close each and every div tag that you
use else you will find your website takes a wonky look to it.
24
All about div tags Introducing HTML
25
Introducing HTML Create a three-column layout
HTML and CSS essentially allow for a huge range of freedom when designing your pages, but there are
a few layout principles that have developed over the years which it’s a good idea to follow.
If you have a quick look at some of your favourite sites on the internet it’s quite likely that they will
use a column layout, akin to a newspaper. A common layout for a site is to have the site or company
logo at the top of the page, then have a column down the left for navigation or links, a main content
section in the centre, and then a sidebar on the right with supplementary information or Facebook
and Twitter feeds. This is then commonly rounded off with a site-wide footer containing copyright
information, the name of the site designer, site links and sometimes a contact address. This tutorial
will show you how to code up the HTML scaffolding for a three-column layout using modern HTML5
elements. Once you have mastered this, it can then be adapted into a two- or more-than-three-column
layout if you so wish.
26
Create a three-column layout Introducing HTML
27
Introducing HTML Create a three-column layout
Adding comments
The container
The header
Navigation items
09 The top element to our page is
usually referred to as a ’header’
and contains the site title, logo, 11 To add links to the navigation
we use the <a> or anchor tag.
First column
navigation, and sometimes adverts. Eg <a href=”products.html”> Products
To create a header we use the header
tag, which is new in HTML5. To open
</a>. If you don’t yet know your exact
site layout, it’s common to use a ’#’ in 12 Now we can add our first
left column. This goes after
the header tag, but still within our
it enter <header> and then to close, place of the link. A hash symbol can
container div. Add this in with <div>
and then don’t forget to close: </div>.
Again, you can give it an ID or class,
“The top element to our page is usually such as:
referred to as a ’header’ and contains the 001 <div id="col1">
002 </div>
site title, logo, navigation, and adverts” This column might contain a menu or
adverts, for example.
28
Create a three-column layout Introducing HTML
Second column
“The second column is usually the widest
13 The second column is usually
the widest in the centre, and in the centre, and normally houses the
normally houses the main page
content. Add it to the page the same
main page content”
way as before, but give it a different
ID this time.
001 <div id="col2"> footer>. Place this after your sidebar The end result
002 </div> column in the code.
Don’t be concerned if you can’t see
any content within your browser – as
without styling, divs are essentially
001 <footer>
002 Footer
003 </footer>
18 Save the file now, making sure
to have the .html extension
at the end. Open the file within a
invisible and only the content browser to see the result. As there is
contained is displayed. Metadata (optional) no styling applied yet, it won’t look
particularly attractive by any means,
but you’ve created a basic web page
16 If you know what content
is going into the pages and
wish to improve search engine
layout that’s now ready for CSS and
content to be added.
optimisation, you can add meta 001 <!DOCTYPE html>
information to the head. Meta 002 <html>
information helps Google and other 003 <head>
search engines to index and organise 004 <title>
sites by content. The meta description 005 3 Column Layout
tag is used to give a short account of 006 </title>
Third column the page content: 007 <meta charset="utf-8" />
008 <meta name="description"
001 <meta name=“description" content="Fishing in Dorset">
29
ANDROID LANDSCAPE 320 X 240
Style. CSS
An introduction to CSS
30
Introducing CSS
An introduction to CSS Introducing CSS
An introduction to CSS
If HTML provides the structure for a website, CSS provides the form. This is the
language that will make your site stand out
C
ascading Style Sheets, commonly abbreviated to CSS, is a language used for
describing how HTML should be presented. CSS documents provide all the format,
colour, positioning and other characteristics of a design that you will see on virtually
any webpage.
Originally introduced alongside HTML4, the language was designed to separate the structure of
a document from the presentation, improving the control of a design for web designers. CSS also
helped to improve accessibility of web pages, reduce HTML code complexity and crucially the
amount of repetition of markup that had to be created to describe how a page should look.
As well as these benefits, the separation of form and function allows different designs to be
displayed to users according to their device, simply by providing a different stylesheet. This means
that, for example, a mobile phone can load the same web page as a desktop browser, but present
the content within the page in a different manner. Similarly, CSS can be used to present page
content one way on screen and a second when printed, or to provide direction to screen reader
software over areas for emphasis.
Additionally, CSS is user-configurable, so while the designer might specify that text should be
shown in 18pt red Arial, the visitor to their site can load their own stylesheet to show the text in
12pt blue Times instead, should they wish to. As you can see, CSS offers a great deal of flexibility by
design. To fully understand what it’s capable of, we need to look a bit more at what CSS is, why
31
Introducing CSS An introduction to CSS
Recent versions of web browsers have vastly improved their implementation of CSS standards
32
An introduction to CSS Introducing CSS
CSS3 opens
the web up
to more users
by allowing
individual
stylesheets
on pages
33
Introducing CSS An introduction to CSS
34
An introduction to CSS Introducing CSS
Positioning
elements
One of the most common
areas of CSS that new
designers struggle to grasp
35
Introducing CSS An introduction to CSS
floating element. This system positioning, and especially fully understand those issues
allows elements to push to float, works. it’s worth taking a quick trip
one side or the other of the down memory lane.
containing element, with History and When HTML3.2 was
content and other elements potential hiccups released, a series of new tags
automatically flowing around By now you’re starting to see were added that allowed web
it. This takes some the value and potential of CSS, designers to specify different
understanding and but it’s not all as perfect as it visual characteristics for their
experimentation, but is might at first seem. There are content. These included the
fundamental to achieving a number of problems that likes of <font>, <b> (for bold
some common layouts so it’s web designers have to text), <color>, <center> and
worth spending a little extra overcome when using CSS to many more. These tags
time getting to know how style their web pages, and to provided the control over
presentation that web
designers were craving, but a
“CSS offers absolute positioning of an problem quickly emerged: by
element according to set co-ordinates” mixing style with content the
pages designers worked on
36
An introduction to CSS Introducing CSS
quickly became
unmanageable, especially
when a web site had lots of
pages. Something as simple as
changing the font a website
used might have taken days to
change, working through
each HTML page in the
website and changing
references from one font
to another.
As a consequence, the W3C
quickly realised that content
should be separate from differences in opinion, both The arrival of
presentation, and developed these popular browsers had HTML5
CSS. CSS1 debuted alongside their own bugs and quirks As the web has matured, so
HTML4 in 1996, but it wasn’t that resulted in strange have the technologies used to
until some years later that web behaviours when interpreting create it and CSS is no
browser vendors had and rendering CSS. To further different. HTML is now just
managed to fully implement compound the issue, as the about at version 5, and CSS3
the language. In the web was taking off and first came into existence at the
meantime, a newer version of becoming mainstream, once beginning of the century. It’s
CSS had been created in 1998, the damage had been done only in the last couple of years
and Netscape and Internet there was no easy way to that either technology has
Explorer version 6 had both backtrack. The net started to be properly
partially implemented CSS2. consequence of these implemented by browser
As well as the slow unfortunate events was vendors however, and the
implementation, from the that web designers had to combination of HTML version
start there were issues with start using workarounds to 5, CSS version 3 and JavaScript
the way the CSS specification code different style rules is often referred to collectively
had been written, leaving for different browsers, as HTML5 (erroneously it must
room for individual taking into account the be said!).
interpretation over what each bugs, quirks and differences As mobile devices have
part of the specification in rendering. become increasingly popular,
meant. This resulted in
Internet Explorer rendering
styles in one way, while the
“It’s only in the last few years that
other popular browser of the technology has been implemented
day, Netscape, rendered properly by browser vendors”
differently. As well as
37
Introducing CSS An introduction to CSS
driving the desire for access Differences of ratified by the W3C. To ensure
to the web on the move, opinion compliance, vendors prefix
and across different screen Despite the recent strides these properties with a name
sizes, so the browser vendors towards adoption of CSS3, and that represents the browser’s
have been coaxed into the retirement of Internet maker. So, for example, to
accelerating their Explorer 6 by Microsoft, there create a CSS drop shadow we
implementations. This has continues to be quite a lot of currently have to have a rule
provided quite a relief to web differences between the way that specifies properties for
designers who only a year ago different browsers render CSS. box-shadow, -webkit-box-
were still implementing The most common issue shadow, -moz-drop-shadow,
workarounds for Internet today is where browsers ms-drop-shadow and
Explorer version 6 – a implement CSS properties o-drop-shadow. The first
decade-old piece of software! that haven’t yet been fully property is the actual CSS3
38
An introduction to CSS Introducing CSS
<above> CSS allows websites to be tailored according the device upon which the website is accessed
specification property, web designers the new browser vendors. And as for
while the others are the opportunities CSS3 the future? Don’t expect to
early implementations by presents are slightly offset by see it any time soon, but CSS4
Safari and Chrome, Firefox, the continuing need to has been in development
Internet Explorer, and provide browser-specific since 2009. It’s still in early
Opera respectively. properties for most of the draft of course, but promises
Vendor prefixes are the modern properties. all manner of exciting new
subject of much debate styling options and properties.
currently as they’ve become What does the If we’re all still designing
more prevalent in recent future hold? websites in another ten years,
years as vendors rush to As you’ve read, CSS3 is still no doubt we’ll be discussing
outdo each other in their being implemented and matching selectors and
CSS implementations. For defined by both the W3C and reference combinators!
39
Introducing CSS Styling with CSS
background
Background is a property that will
determine how the background of an
element is styled. It has many associ-
ated properties eg background-color,
background-size.
border
The border property, as its name The background property
allows for background
suggest adds a border to the images which can enhance
associated element. Borders can be any design
added to all sides of an element or a
specific element such as the top, right,
left or bottom. There are several styles another element. Float has two main 2. The default option is normal and is
eg solid, dotted etc and the option to values left and right. Selecting left often the preferred choice.
chose a width. will position an element to the left.
Conversely, if assigned the right value, margin
box-shadow it will be positioned to the right.
Margins help create space between
The box-shadow property allows content. When adding a 5px margin to
for the implementation of multiple height an element it will create a 5px space all
drop shadows on box elements, ie around the element. Margins can be
div elements. It can specify values for This is as simple as the name separated so it is only applied to one
color, size, blur and offset. Text-shadow suggests. The height of an element is part of an element eg margin-top.
uses the same principles but applies determined by the height property.
the drop shadows to text. This can be a fixed height using pixels max-height
or a flexible height using percentages.
font-family The max-height property ensures that
letter-spacing an element does not exceed a specific
Fonts can be styled individually or height. It is often used in conjunction
as part of a family. The font-family To improve legibility and add flexibility with max-width, which ensures that
property is used should the first to web typography the letter-spacing an element doesn’t exceed a specific
choice font not be available then a property can be used. The value eg width. Both properties are typically
replacement option can be called 2px will add the stated space between
upon. These will be set out in the each letter of the styled text.
value. Eg verdana has a font family that
includes a bold and light option. line-height “Margins help
float Line height is the space between the create space
lines in text. The line-height property
The float property is used to position can use a fixed value with pixels or between content”
an element specifically within alternatively use a number value eg
40
Styling with CSS Introducing CSS
text-decoration
The text-decoration property specifies
what can be added to text. You can
add under- and overlines and a strike
through to your text.
value
The value element is associated
<above> The width and height property determine how every element on a page is sized with a property and selector. It will
used in responsive designs to ensure specifically determine how a property
position is styled. For example, if background-
that a design display as intended.
colour is the property the value
There are four values for the position will be the appropriate code colour
overflow property, the default is static. The eg #CCCCCC.
others are absolute, relative and fixed.
If an element has content that extends
beyond its containing element, for width
property
example, an image, the overflow
property can be called into action. If The width property is typically used in
There are hundreds of properties combination with the height property.
the hidden value is used the image in CSS, these are accompanied by
outside of the element will be hidden. A fixed width can be determined by
a selector and value. They tell the using pixels. To makes sure an element
Using scroll will add scroll bars so all browser how a certain part of the
the image can be seen. is full width of an element or page its
related HTML element will be styled. can be set to 100%.
padding selector z-index
Padding is very similar to margin, A CSS selector is the identifier that is
except the padding is applied to the The z-index property determines
link to HTML. The selector will refer to a the stack order of an element. An
inside of an element. If text is to close HTML element eg h1, h2. The browser
to the top of an element adding element with greater stack order, for
will then read the style information example 100, is always on top of an
padding will give it breathing space. (property and value) in the selector element with a lower stack order.
and apply it to the HTML element. Note that the z-index property only
works with positioned elements such
syntax as position:fixed;.
text-align
<above> The spacing between lines of text can
Text can be aligned to the left, right
be adjusted with line-height making the text or centre of the element the text <above> Adding shadows to text is simple using
more legible the text-shadow property
41
Introducing CSS Centre your page
When you’re designing a webpage, you have to remember that a browser window can be almost any
shape and size. Desktop computers have a wide range of screen sizes, and mobile phone and tablets
are used to browse the web too. Your nicely designed page could be ruined if you simply allow it to
flow into the browser window regardless of the latter’s size or shape. By creating a wrapper you can
specify the width of the webpage content and its position in the browser window. It is an essential part
of the design process.
’Wrapper’ is a commonly used name for a piece of CSS code that is used with a div tag to
size and position the content of a webpage. A div tag is placed at the start of the page content just
after the opening body tag and again just before the closing body tag, thereby enclosing or wrapping
the content.
In CSS we can define how everything between the div tags is displayed. It can be centred on the
page, positioned a certain number of pixels from the left, a border can be added, its width can be fixed
or variable and so on. It is an essential component of any webpage and it’s quite straightforward.
Set the
margins
Without margins
Borders or the page content
borderless? is displayed on
This page has the left. You can
borders, but they manually set them
are optional and by entering the
leaving out these number of pixels,
parameters will but a good option is
remove them. to set them to auto
It’s your choice. to centre the page
Padding, just
above, is used for
extra spacing, but
it isn’t needed
42
Centre your page Introducing CSS
The CSS link Flexible page width is set to solid. Alternatives include
dotted, dashed, double and ridge.
001 div#wrapper {
002 width: 750px;
06 Your page design may look
good if there is a border, and
this specifies one that is two pixels
003 }
wide. The border colour is set to dark
green (006600) and the border style
Every webpage contains text and it is frequently the main content. Therefore you should ensure that
it looks good by choosing the fonts and styles to fit your design and the image you want to portray.
There might only be a small amount of text if the main content focuses on images, but even so, there
will be titles, links and captions. There’s no getting away from text on webpages.
You can add CSS code to a webpage to define how the text is displayed, but placing it in a
separate .css file and linking to it in the page’s head section means that the same text styles are
applied everywhere in your site. HTML font tags have been replaced by CSS font-family definitions, old-
fashioned <i> and <b> tags are no longer needed, and font-style and font-weight enable you to set the
styles to normal, italic, bold and so on. It might seem like extra work for one webpage, but when you
are creating a site with 100 pages it is a considerable time-saver.
Writing the CSS rules for the text is simple and you can create a class that defines a text style
and then use it over and over again in the page. We only look at headings and body text here, but
expanding the CSS yourself should not present any problems.
44
Define body text and heading styles Introducing CSS
around it or the CSS won’t work. It is define three styles of text. It varies the
also a good idea to offer an alternative font-style and font-weight, but you
Define the headings
font in case the visitor to your site could also create small text, large text,
doesn’t have the one you specified.
Choose a family such as serif (fancy) or
styles for panels, captions for images
and so on.
06 In addition to body text, there
are also headings using h1 to
h6 tags. You don’t need to define all
sans-serif (plain). of them, just the ones you use. Do
001 p.normal {
002 font-family: Verdana, sans-serif;
it exactly like the p tag and set the
001 p {
002 font-family: Verdana, sans-serif; 003 font-size: 14px; font, size, style and so on. We’ve also
003 } 004 font-style: normal; reduced the bottom margin below
005 font-weight: normal; the header.
006 }
007 p.italictext { 001 h1 {
008 font-family: Verdana, sans-serif; 002 font-family: Arial;
“You can create a 009
010
font-size: 14px;
font-style: italic;
003
004
font-size: 30px;
font-weight: bold;
class that defines a 011
012
font-weight: normal;
}
005
006 }
margin-bottom:-10px;
45
Introducing CSS Style your lists to stand out
Although some web pages may require a lot of text, it is generally best to keep it brief and to the point.
People scan a page for interesting content and then move on if they don’t spot anything straight away.
Lists are therefore very useful for drawing the visitor’s attention to some content and for presenting it in
a way that can be digested quickly.
The HTML <ol> and <ul> tags are used to create ordered (numbered) and unordered (bullet) lists,
which we explored on p22. They are useful if unexciting, but with CSS list-style-type you can change the
bullet to different shapes like a circle or square. It is even possible to replace it with an image specially
created to fit in with your site’s design and colour scheme using list-style-image. You can change the
font used to display lists so they match the body text. If you have used HTML lists you will have noticed
that they are indented, but with CSS you have fine control over the positioning using padding and
margins. You can tighten up the layout or space it out – it’s your choice.
Customise
your lists
Create a class
001 .liststyle {
002 list-style-type: square;
003 }
46
Style your lists to stand out Introducing CSS
001 p. ul{
07 As we’ve discussed, each HTML
element can have a border. We
haven’t specified one so far, so one
002 font-family: Verdana;
hasn’t been drawn. However, we can
Boxed lists 003
004
padding: 10px;
font-size: 14px; easily define one by setting border-
005 } width to the number of pixels and
02 CSS displays each element
of web page content in a
series of boxes. This means that a list Choose a background
border style to dotted, solid, dashed,
double, groove, ridge, inset or outset.
defined by a ul or ol tag is separated 001 border-style: dotted;
from other elements on the page by
a margin. Inside the margin there may
be a border, but it is optional and not
05 Many HTML elements can
have a background colour and
it is applied to both the content and
002
003 }
border-width: 2px;
always used. Between the border and padding areas, but not the border
the content is padding or space. or margin. A background-color of Colour the border
#ffd0d0 has been set, but if you are
not familiar with this notation, you can
use common names like red, yellow,
08 Most parts of the list can be
coloured and this includes the
border. The border-color has been
blue and so on. This is less flexible,
set to #800000, which is a medium-
though, hex codes can be easily found
dark red. It’s a good idea to specify
on Photoshop or online.
the colour even if it’s black, because
001 background-color: #ffd0d0; } default settings for one web browser
might be different to the defaults in
Position the list another. Better to be safe.
Inside vs outside
001 border-width: 2px;
03 With those boxes in mind, we
can position the list within
the space allocated to it on the page. 06 You’ll notice that the bullet
blobs are outside of the
002
003 }
border-color: #880000;
Padding and margin have been added background colour. This is their default
to the liststyle class and set to 10 and position, but it’s possible to change
0 pixels respectively. Experiment with this and make them appear in the
different values to see how they affect background area. In this step, list-style-
the position of the list. position is set to inside and this makes
the list look more attractive.
001 padding: 10px;
002 margin: 0px; 001 list-style-position: inside;
003 } 002 }
DIY bullets
Style the text over the list’s png), which tells the browser to use
an image called bullet.png that we
positioning created earlier in a paint program and
04 Notice in the last step that the
list text has a different font to using padding saved with the web page.
the body text. That’s because no style
is set for lists. We defined the font and and margins” 001 border-color: #880000;
002 list-style-image:url(bullet.png);
size for the body text in a previous 003 }
47
Introducing CSS Turn lists into navigation bars
Website navigation is an important topic and it is something that you need to put some thought into as
you are designing your website. At one time we would have used button images created in a paint or
photo program and then used JavaScript to create a rollover effect when the mouse hovered over one.
But that’s yesterday’s technology and modern sites use CSS instead.
A CSS navigation bar looks like a regular unordered list in the HTML of the page, but using CSS we
can manipulate the list elements and turn them into the website’s navigation. Instead of the list running
down the page, the list elements can be displayed across it instead. We can style the links just like any
other text and create a custom look for the navigation bar. The result looks nothing like its original plain
HTML layout and it really shows off the power of CSS.
You can copy the code into your own web pages and it will work fine. All you need to do is to
change the link text to correspond to the pages or sections on your own site, and style the text to fit
in with the fonts and colours that you use. It is really quite straightforward once you see how it works
for yourself.
STRETCH IT TO FIT
In the finished screen shot the navigation
bar stretches across the full width of the
page. There are several ways to achieve this
and in this case we have simply chosen a
width for the list items that exactly, or near
enough, fit across the page. If you have
more navigation items you will need to
reduce the width or make the page wider.
48
Turn lists into navigation bars Introducing CSS
Create a list breaks by using float. Setting the a to change the way that <a> links
list elements (#navbar li) to float left look in <li> items. Set the font size
causes them to be displayed one and weight, margin and padding, and
01 An unordered list (ul) is used to
provide links to other sections
of the website. It’s all standard HTML
after the other on the same line, like a
navigation bar.
so on.
001 #navbar li a {
and it’s exceedingly dull compared
001 #navbar li { 002 display: block;
to CSS. Try it and see. In the ul tag 003 width: 140px;
002 float: left;
though, we have added id=”navbar” 003 } 004 font-weight: bold;
and we’ll use it to change the way the 005 margin: 0px;
list is displayed. 006 font-size: 20px;
007 padding: 5px;
001 <ul id="navbar" 008 }
002 <li><a href="index.html">Home</a></li>
003 <li><a href="news.html">News</a></li>
004 <li><a href="walks.html">Walks</a></li>
005 <li><a href="contact.html">Contact</a></li>
006 <li><a href="about.html">About</a></li>
007 </ul>
Spread them out
Make it plain
set its width to 140 pixels.
001 #navbar li a {
06 Three items have been added
and immediately noticeable is
the colour. The text colour has been
02 In the last tutorial we saw how
to style lists and the bullets can
be removed by setting list-style-type
002 display: block;
003 width: 140px;
004 }
set to dark green and the background
has been set to light green with
color and background-color. Finally,
to none. The padding and margin can
text-decoration:none removes the
also be set to zero. This produces a
underline from the links.
very plain list of links at the top of the
page that’s not very exciting. 001 #navbar li a {
002 display: block;
001 #navbar { 003 width: 140px;
002 list-style-type: none; 004 font-weight: bold;
003 margin: 0px; 005 margin: 0px;
004 padding: 0px; Style the text 006 font-size: 20px;
005 } 007 padding: 5px;
A webpage would be pretty dull without any images on it! Some images may appear on every page,
such as a graphical website logo or heading, while others may be specific to each page. You will need
to create the images for your site before you start. Remember to use them sparingly and keep the file
size as small as possible to ensure that webpages load quickly for visitors.
Images are inserted into webpages using the HTML <img> tag and there are attributes to position
it left and right, set the size and so on, but those are dated. If you use CSS to format images instead,
there are many more options available to you. For example, you can add a border, set its thickness
and its colour. The spacing around each side of the image can be individually adjusted, text can be
wrapped around it on the left or the right and so on. The latest web browsers that are up to speed
with CSS version 3 can display advanced image attributes like drop shadows that give the page a
3D look.
Forget the old HTML way of doing things and take advantage of CSS and its powerful features. Our
tutorial will guide you through the process.
Format images using CSS Introducing CSS
51
Introducing CSS Add a background image
The fewer images your website has, the faster it will load, but plain colours for the background and lots
of text might be a turn off for your visitors. A few key images can greatly enhance the look of a website
and a background image has the advantage of being used on every web page. This means that the
browser only has to download it once and then it caches it ready to be used on the next page. The end
result is a great page design with no time wasted downloading large images.
In this tutorial we will start with a plain coloured background and then show how to add an image.
It can be a large one that fills the browser or a small one that can be stretched to fill or tiled across or
down the screen. Tiled images are great for reducing the size of a page because they are so small (for
more information on how to create your own, check out page 160). If you use a large image you must
bear in mind the size of the file and try to minimise it without affecting the quality.
Create an image The background colour
Load your photo editor or paint program. Create The background colour of the page is set using
an image or find some clipart that you can use as CSS definitions in the body tag. It is set to the
is or easily modify. Save it as a compressed JPEG or same colour as the background for the image so
256-colour PNG the two blend in like one
Background
Set the repeat wrapper colour
In this case we want a single image If no background colour
that is not repeated in either the is set for the wrapper, the
horizontal or vertical directions, background colour of the page
so background-repeat is set to will show through. It’s up to you
no-repeat. Tiled images repeat in whether you set a #wrapper
both directions background colour
52
Add a background image Introducing CSS
Impressive backgrounds
A background wrapper
Modify the wrapper
03 As well as inserting an
acceptable number of
05 Here, the background is solid,
but the text is on an image.
Anything can have a background,
hyperlinks, you can also flag up certain so we can move background-
content. Place words and rogue image:url(‘back2.jpg’) from the body
websites, IP addresses and emails in tag to the #wrapper definition. We
Pick a colour this box and any posts containing chose a paler picture!
such content will immediately be
001
002
body {
background-color: rgb (128,128, 128); “Tiled images are great for reducing
003
004
background-image:url('back1.jpg');
} the size of a page”
005
53
Introducing CSS Add a background image
Horizontal gradients
Use smaller images See through wrapper
Tile it across
Create a gradient
10 Now this is far better. What
we’ve done here is to add:
Tile it down
08 We have created a small image
that has a simple gradient that
runs from dark green at the top to 001 background-repeat:repeat-x;
12 The image has been tiled down
the screen, but not across it.
white at the bottom. This will be used to the CSS in the body definition. This This is because of the background-
as the background for the page and instructs the browser to repeat the repeat:repeat-y; instruction in the CSS
even when exported at a reasonable image across the page only (the x code for the body tag. It is possible to
quality it doesn’t create a very big direction). The background colour is repeat either in the x (horizontal) or y
file. Tiled backgrounds are great for set to white, which is the final gradient (vertical) directions. If you don’t specify
creating fast-loading web pages. colour so it blends in. then it is tiled in both directions.
54
Add a background image Introducing CSS
Background positioning
55
Introducing CSS Style a two-column layout
56
Style a two-column layout Introducing CSS
57
Introducing CSS Style a two-column layout
CSS reset
The header
10 Now, for the header section we are going to float it left and give it a width
of 100%, which will guarantee our header spans the whole width of our
‘#wrapper’. Then we push the header down 10px using margin. Here we have
used what is called shorthand CSS, which enables us to only pick the top margin.
Now give the background a colour and then 100px height. The sidebar styles
001 #header {
002
003
float: left;
background: #f1f1f1;
12 The sidebar will be positioned
to the right-hand side and
this is at most expected by the user/
004 margin: 10px 0 0 0;
005 width: 100%; visitor. So it makes sense to float to
006 height: 100px; right. And then use margins again to
007 } give us some white space. Our sidebar
background will be a darker grey than
Main content styles the rest and it will be a fixed width of
324px, which should give us plenty of
11 Now to add some style. First thing is to float it left. Then give it an off-
white background colour and then by using margins we can give it some
breathing space. We then specify its width and height taking into consideration
room for any inner content. Then we
give it the same height as the main
content section.
the overall width of our wrapper so we have enough room for our sidebar.
001 #sidebar {
001 #main_content { 002 float: right;
002 float: left; 003 margin: 10px 5px 5px 6px;
003 background: #f0f0f0; 004 background: #ccc;
004 margin: 10px 5px 10px 0; 005 width: 324px;
005 width: 620px; 006 height: 630px;
006 height: 630px; } 007 }
58
Style a two-column layout Introducing CSS
Research alternatives
Be inspired
18 The two-column layout is in
no way the be all and end all.
Within this book you will find the tools
to create a three-columned layout,
17 Now you’ve finished your basic two-column layout, take at look at some
of your favourite websites and see which layout they employ. As shown
above, www.webdesignermag.co.uk uses a two-column layout too.
and be able to learn the skills your
acquire to customise any layout to
whatever you have chosen.
59
Introducing CSS Create a header
Create a header
Learn how to create a clean, simple and effective header for your website
Having clean and clear header for your website can be the difference between a successful and user-
friendly experience and a cluttered and disorganised website that no one will want to visit again! You
don’t want a first-time user coming to your site and not know how your navigation works, or your
company branding (logo) hidden under a load of over-useless graphics or text – it doesn’t even really
matter how effective the rest of your layout is.
Yes, this sort of thing has been known to happen (more often that web designers would like to
admit!) and this is why so many designers are turning to a relatively new role called user experience
or ‘UX’. So in this tutorial we will take a look at how we can create a simple, clean and useful header for
your site.
60
Create a header Introducing CSS
001 <body>
We are going to use an ID again and
002 <div id=”wrapper”>
call it ‘logo’. Then we will wrap it within
003 <div id=”header”>
an anchor tag and link it to our page 004 <a href=”index.html”><div id=”logo”></div></a>
by adding in the index page within ‘<a 005 <ul class=”navigation”></li>
href=”index.html”>’ 006 <li><a href=””>home</a></li>
007 <li><a href=””>about</a></li>
001 <body> 008 <li><a href=””>blog</a></li>
002 <div id=”wrapper”> 009 <li><a href=””>portfolio</a></li>
003 <div id=”header”> 010 <li><a href=””>services</a></li>
004 <a href=”index.html”><div 011 <li><a href=””>contact</a></li>
id=”logo”></div></a> 012 </ul>
005 </div><!-- END header --> 013 </div><!-- END header --> </div>
006 </body> 014 </body>
61
Introducing CSS Create a header
The footer
06 Now we are going to centre our header and content using the ‘wrapper’
div. What we are doing here is making sure we have no margin at the
top or bottom and automatically find the difference on the left and right that
idea of where we need our logo and
navigation, which we will add in over
the next few steps – then once happy
is in relation to our fixed width – which we set to 960px. 960 pixels is mostly we will remove it.
used because it fits nicely within the lowest common denominator of screen
resolutions (1080 x 760). 001 #header {
002 float: left;
001 #wrapper { 003 width: 100%;
002 margin: 0 auto; 004 height: 250px;
003 width: 960px; 005 border: 1px solid #f00;
004 } 006 }
The logo
62
Create a header Introducing CSS
Navigation anchors
12 Now let’s style our page content. While we’re here let’s get sneaky and add
some CSS3 properties to make the background have rounded corners by
using ‘border-radius: 6px’. We then style the paragraphs give it some padding to
13 Looking at our navigation, we
can clearly see that it doesn’t
look very attractive. So let’s spruce
both the paragraph text and header tags. it up somewhat by heading over to
Google Fonts www.google.com/
001 #main_content { fonts and type in ‘lobster’ within the
002 float: left; search field and you should see at
003 width: 900px;
least two choices of fonts. The one we
004 height: 400px;
want is the top style. Then click the
005 background: #fff;
006 border-radius: 6px; blue ‘add to collection’ button to the
007 } right and now it ready to use.
008 #main_content p, h2 {
009 line-height: 22px; Google font-family
010 margin-top: 10px;
011 padding: 20px;
012 }
15 Now let’s copy the ‘font-family’
property and then open up
the ‘styles.css’ file and locate the
Apply the Google font ‘.navigation li a’ rule (a CSS rule is
everything within the curly brackets)
14 The next step is to click the ‘use’ grey button located at the very bottom
right and scroll down the page slightly. What we have first is the ‘link’ tag
line that will link straight to the Google font servers and will always be available.
and paste the new ‘font-family’
underneath the ‘font-size’ property.
That way you can guarantee everyone will be able to see your chosen font. Copy
001 .navigation li a {
the link to your clipboard. Then paste it into your ‘index.html’ file just underneath 002 float: left;
our other CSS link within the ‘<head>’ tag. 003 color: #333;
004 padding: 6px 20px;
001 <!-- CSS --> 005 text-decoration: none;
002 <link rel=”stylesheet” href=”styles.css”> 006 border-right: 1px solid #333;
003 <link href=’http://fonts.googleapis.com/css?family=Lobster’ rel=’stylesheet’ 007 font-size: 16px;
004 type=’text/css’> 008 font-family: ‘Lobster’, cursive;
005 </head> 009 }
63
Introducing CSS Create a sidebar
Create a sidebar
Learn how to create a clean navigation system for your website
A sidebar is without doubt the area that is most often created by web designers, because it’s the most
needed. It can hold all sorts of content: things such as extra navigation links, a search field and perhaps
some small thumbnail images that relate to your website – it can be anything.
So in this tutorial we’re going to create a simple page layout that has a functional navigation and a
nice and simple sidebar that includes some content within. We’re going to include within the sidebar
a list of links for that extra navigation we mentioned and a search bar above and also some thumbnail
images at the bottom to act as though we have a Flickr section – very useful for any photography-
based sites. So open up your favourite text editor and let’s get started.
The width
A thin-looking sidebar
wouldn’t help anyone
unless you have no intention
of anything but small
thumbnail images!
Navigation
Having a list of links for an
extra navigation will allow you
to add in links that you may
not have had the room to fit in
the main navigation menu
The thumbnails
We added this feature
because you see it all the time.
People who have a blog can
use a plugin that allows them
to feature their Flickr photo
64
Create a sidebar Introducing CSS
Sidebar navigation
05 Open up your ‘styles.css’ file and at the top add in the universal selector
that will allow you to reset every element(<p>, <h1>, div, etc) to zero
margin and padding. Then using the ‘body’ tag we can set the background
06 So with our wrapper acting
as a container for all our page
content, we can center everything
colour to an off white ‘#f1f1f1’ and set our default font style and size. using a fixed width and margin. We’re
specifying 0 pixels on top and bottom,
001 * { with auto margins on the left and
002 padding: 0; right. This is an easy and most often
003 margin: 0; the best way of centring your page on
004 }
your screen.
005
006 body {
007 background: #f1f1f1; 001 #wrapper {
008 font-family: Verdana, Geneva, sans-serif; 002 margin: 0 auto;
009 font-size: 12px; 003 width: 960px;
010 } 004 }
65
Introducing CSS Create a sidebar
001 .navigation {
002 float: right;
003 margin: 150px -50px 0 0;
004 width: 600px;
005 }
006 .navigation li {
007 float: left;
008 list-style: none;
009 }
010 .navigation li a {
011 float: left;
012 color: #333;
013 padding: 6px 20px;
014 text-decoration: none;
015 border-right: 1px solid #333;
016 font-size: 16px;
017 }
66
Create a sidebar Introducing CSS
The sidebar
67
Introducing CSS Add content to your website
The top section The middle section The bottom section The width
It’s a good idea to add We have added a video The bottom section is again You will need to think
some text about your from YouTube here, but of used as a text-based section about the width of your
website so users can see course this could just as easily that describes the middle main content area(s) and
what you are all about be a image of your company section video plan ahead accordingly
before going any further or yourself!
68
Add content to your website Introducing CSS
02 Now in this step we are going to give our main content area a title that will
welcome everyone to the website. We do this very easily by adding in a
‘<h2>’ tag and a nice message within. What we will do is use CSS later to see what
we can do to make this look a little nicer.
Getting started
Welcome text
Adding an image
03 Now we need to add some
‘welcome’ text. This is normally
a good way of letting the user know 04 Now we can add in an image within our welcome text. The idea here is to
have a small thumbnail image of something that relates to the website. So
what your website is all about from place your image tag ‘<img src=’ above the welcome text just sitting underneath
the off. Here we will just wrap about the header. Then we will use CSS later to float it to the right.
three or four sentences within some
‘<p>’ tags. 001 <img src="imgs/thumbnail.jpg" height="100" width="100" class="main_thumb">
Content image
05 Let’s open up our ‘styles.css’ file. We can point to the ‘#main_content’ div
and then hock onto the ‘p’ tag. We can then use multiple selectors here
and use the same style properties and values for the<h2> tag.
thumbnails. Then we’re going to make
sure we have enough white space
around the image.
69
Introducing CSS Add content to your website
001 #main_content{
07 Next we want to add the video to our main content area. Now we can get
really technical and use an HTML5 or flash player here, but to keep things
really simple, we can shoot over to youtube.com and copy and paste the embed
002
003
float: left;
height: 100%;
004 width: 630px;
code within our ‘index.html’ page. Then we want to be able to shift this video about 005 background: #fff;
using CSS, so it would make sense to wrap a div around it with an ID of ‘video’. 006 border-radius: 6px;
007 margin-bottom: 40px;
001 <div id="video"> 008 }
002 <iframe width="420" height="315" src="http://www.youtube.com/embed/
003 kNn44gHqanM" frameborder="0" allowfullscreen></iframe>
004 </div> Horizontal rule
Positioning the video
10 What we are going to do now is
add a separator just above the
09 All we are going to do here is position the video using CSS. Now it makes
sense to float the video left. Then we are going to use margin to push it
away from the edges and anything that may be surrounding the video will now
video. This will be easily styled using
CSS, so we won’t need to depend on
some graphic design software such as
have a generous amount of white space. Then let’s add a black 5px border to Photoshop or Fireworks. It’s simply an
finish off our video. HTML tag called a horizontal rule ‘<hr>’
and we can add that just above the
001 #video { video div within our ‘index.html’ file.
002 float: left;
003 margin: 20px; 001 <hr>
004 border: 5px solid #000; 002 <div id="video">
005 }
70
Add content to your website Introducing CSS
13 So the next step would be to add in some more text that could be used for
a summary/excerpt of our video. Underneath our new thumbnail image,
place some more dummy text that is wrapped within paragraph tags ‘<p>’ with a
14 What we need to do now is
style our new content using
some simple CSS. So, open up
class name of ‘vid_excerpt’ so we can style it using CSS. your ‘styles.css’ file and position our
thumbnail image first. We will float it
001 <img src="imgs/thumbnail.jpg" height="100" width="100" class="main_thumb2"> left and then give it a 40px margin all
002 <p class="vid_excerpt">It is a long established fact that a reader will be
around. Then to finish it off we can give
003 distracted by the readable content of a page when looking at its layout.
it the same subtle drop shadow as the
004 The point of using Lorem Ipsum is that it has a more-or-less normal
005 distribution of letters, as opposed to using ‘Content here, content here’, other thumbnail we used in the sidebar.
006 making it look like readable English.
007 </p> 001 .main_thumb2 {
002 float: left;
003 margin: 40px;
004 border: 1px solid #fff;
005 box-shadow: 0px 4px 6px #999;
006 }
Bottom content
001 hr {
002 color: #ddd; Going further
003 width: 570px;
004
005
006 }
margin-left: 20px;
float: left; 18 As we said in the intro text to this tutorial, it’s down to you as to what
your content should include. Later in this book we explore adding maps,
newsletters, image sliders and more!
71
Introducing CSS Add content to your footer
In the past, the humble footer was not much more than a slim strip of colour with nothing more
interesting than the copyright text written within. But in many modern websites, we have seen a huge
improvement in footer designs and the content held within them.
These days, they are a lot higher and contain all sorts of content which can include contact forms,
newsletter sign-up fields, social media integration and much more. Ours for instance, in addition to a
newsletter sign-up field and generic About Us text, features another set of links for navigation, so our
readers don’t have to scroll back to the top or to the sidebar if they want visit another page.
As crazy as it sounds (and this would have sounded incredibly crazy no more than a few
years ago), the footer has really taken the modern web by storm and has now developed into an area
that needs good planning – like all parts of your website, it is important to offer the right amount of
content without confusing the user. So in this tutorial we will build a simple footer and include some
useful content that you would most likely see in a modern layout.
72
Add content to your footer Introducing CSS
Footer background
001 #footer {
002 clear: both;
003 height: 200px;
004 width: 100%;
005 background: #fff;
006 margin-bottom: 20px;
007 }
List items
“The footer has taken the web by storm
07 Now style the list items‘<li>’.
Here we are removing the
default bullet points and then floating
and has now developed into an area that
all the items left, which will push each needs good planning”
one up and next to each other giving
73
Responsive design Introduction to Responsive Web Design
Introduction to
Responsive Web Design
Ultimate guide to discovering responsive web design and
how to start using it today
Responsive web design
With the growing plethora
of internet enabled devices
it is important to ensure
your website is responsive.
Understanding responsive
web design practices will help
you build websites suitable for
every screen size whether large,
medium or small. <above> More websites, including the popular Mashable news website, are becoming responsive
Fluid Layouts
In the past we had liquid layouts, where only the layout columns Quick Tip
structural elements and text were truly fluid which expands and Common responsive
contracts as the browser window size changes. But this was not breakpoints you may want to
truly flexible, images were not fluid which could easily break use http://responsivedesign.
is/develop/browser-feature-
layouts. This included structural layouts which directly broke the support/media-queries-for-
layout if pushed enough. common-device-breakpoints.
This is where fluid grids excels where traditional liquid layouts
failed. Fluid grids are a fundamental key principle of responsive
web design. Rather than designing for rigid pixels or arbitrary
percentage values, we can use grids to provide structure and use
relative units to provide fluidity defined by using maximum width
to carefully design in proportions.
When designing in traditional pixel based unit, there is a formula
we can use to identify the percentage values, by using:
75
Responsive design Introduction to Responsive Web Design
The CSS:
001 .wrapper {width: 960px;}
002 section,
003 aside {margin: 20px;}
004 section {float: left; width: 640px;}
005 aside {float: right; width: 300px;}
To convert the fixed units and turn them relative we can use the
flexible grid formula:
001 section,
002 aside {margin: 2.083333333%; /* 20 / 960 = 0.02083333333 */ }
003 section {float: left; width: 66.666666666667%; /* 640 / 960 = 0.66666666666667
*/}
004 aside {float: right; width: 31.25%; /* 300 / 960 = 0.3125 */ }
We set our context as our wrapper which is 960 and the target value is
either our section, aside and margin. Using this formula we can apply
this throughout our grid to build a dynamic website to scale every
viewport size.
Setting up breakpoints
with media queries
1 Setting up mobile
breakpoints This will be set for
screen width of 320px and max
width of 480px.
77
Responsive design Introduction to Responsive Web Design
2 Add in media query Add a 001 @url(responsive.css) all and (max-width: 960px) { }
media query for screens of a
maximum of 320 pixels.
Most common practice and to avoid further HTTP requests is to just
001 @media screen and (max-width: use @media within your existing style sheet:
320px) { }
001 @media all and (min-width: 600px) and (max-width: 940px) {...}
The above selects all media types between 600px and up to 940px.
Besides setting the min- and max-width we can also use the
orientation media feature to determine if a device in landscape or
portrait mode.
78
Introduction to Responsive Web Design Responsive design
User agents using HTML4 algorithm will now simply ignore media
queries that you have inputted.
1 Serve high-res images to
Viewport retina displays Download
Retina.js at http://imulus.github.
If you built a responsive website and try to view it on a mobile
io/retinajs/.
device you will notice the website has scaled to the desktop size.
By adding a viewport meta tag we can ensure browsers scale the
webpage to fit the screen size its on, with:
Fluid images
2 Copy retina.js to your scripts
Most websites contain some sort of media typically imagery. With folder Copy the plugin to your
a responsive website content is expected to fluidly change to the JavaScript folder.
screen resolution, this implies images will need to as well. Luckily
there is a easy solution to scale images when the viewport changes. 3 Add script to <head> In the
<head> add <script type=”text/
In the CSS simply add: javascript” src=“js/retina.js”></
script>
001 img {
001 max-width: 100%;
001 }
4 Reference retina images For
retina images save them as
Clearfix Media query [email protected]
Using the clearfix hack to automatically clear Percentage grids are placed in a media query
after itself so it won’t be necessary to add based on screens with a minimum width
additional markup of 450px
Quick Tip
Its a good idea to add height:
auto; when using responsive
images in case the height
does not resize in proportion
Zoom: 1 fix Calculated grids
Applying the zoom: 1 to fix old browsers such as This grid structure has 12 columns which are with the width.
Internet Explorer to fix the hasLayout bug broken down into calculated percentage widths
79
Responsive design Introduction to Responsive Web Design
Applying this fix will allow images to scale down dependent on the
Compressing CSS containers width.
80
Introduction to Responsive Web Design Responsive design
Responsive Frameworks
Building a new responsive website can be daunting, with the
technically issues surrounding responsive web design, calculating
number of columns, grids, percentage widths, breakpoints and
further technical hurdles that may appear through development. A
solution is to adopt an existing responsive framework.
There is a huge benefit when relying upon a responsive frame to
begin it won’t be necessary for you to calculate your own fluid grids
instead most modern frameworks will allow you to get going and
Futher reading
starting building your website. Essentially picking up a framework There are a lot more reading
will help save tremendous amount of time and generally they to further your discovery on
responsive web design and
come packed with predefined styles, components, font sizes, form to continue on improving
elements, CSS resets and more. your skills.
Popular frameworks will have an active community and even Websites that contain
great resources on responsive
extend the framework further with new and robust plugins. There web design include This is
will traditionally come with clear documentation for you get started Responsive http://bradfrost.
when using the framework and understanding all the code and github.io/this-is-responsive/
a collection of news and
components available. resources. A beginners guide
Two very popular and well maintained responsive grid to responsive web design
frameworks available are Bootstrap and Foundation. resource list www.targetlocal.
co.uk/responsive-web-
design-resources/.
Bootstrap (getbootstrap.com) originally created by the team from
Books that help further
Twitter, this framework is one of the most popular open source your skills include HTML5 for
responsive framework out there. This library consist of a huge Web Designers http://www.
abookapart.com/products/
amount of components and re-usable functionality such as drop
html5-for-web-designers
downs, glyphicons, styled form elements, progress bars, JavaScript and CSS3 for Web Designers
powered plugins including carousels, alters, tooltips, transitions and www.abookapart.com/
products/css3-for-web-
many more.
designers and Responsive
Web Design www.
Zurb Foundation (foundation.zurb.com/) is one of the most abookapart.com/products/
advanced responsive front-end framework. It was built with speed responsive-web-design all
in mind so all the components and JavaScript plugins have been are by A Book Apart.
Checkout some great
performance tuned. Foundation as the name suggests is used as examples of the best
a starter for any responsive website, it contains a responsive grid responsive websites out
system, mobile friendly navigation, customisable components, there on Awwwards www.
awwwards.com/websites/
some handy media plugins including flexible videos, lightbox and responsive-design/ and
carousel slider. more to see over on Get
with the Future socialdriver.
Which ever framework you choose always make sure you com/2014/03/05/65-best-
carefully read the documentation and make sure it suits the needs responsive-website-design-
examples-2014/.
of your website.
81
Responsive design Bootstrap
Bootstrap
Responsive design made easy
Bootstrap is a powerful yet approachable front-end framework designed to
make it quicker and easier to develop user-friendly websites
It was in August 2011 that Mark Otto, a developer type source file, a forms source file and a tables
at Twitter, announced a new framework that the source file.
social media platform had developed internally, Bootstrap is designed to be mobile-first,
with the aim of providing a consistent API while meaning its fully responsive which includes a
developing the popular micro-blogging tool. powerful four tiered grid system so your layouts
Bootstrap was designed to help Twitter’s can adapt to phones, tablet, desktops and large
developers avoid the mish-mash of competing desktops screens. Given that much of our internet
and incompatible frameworks and libraries. usage is moving onto smaller devices, this seems
It provides a unified toolset for all front-end to be a sensible move.
development requirements including advanced On top of the CSS framework, a series of jQuery
typographical control, a built-in grid system, plug- ins provide functionality such as support for
and the option to use components to extend drop-down menus, modal boxes and much more.
functionality to suit any particular needs that go Taken together, these different elements
beyond the basic framework common to every provide the basis of a plug-and-play, standards-
website. Twitter have since produced one of their compliant and user- friendly HTML5 website. The
most compatible and functional websites to idea is to facilitate rapid application development
date, with the sleek new design not only being without having to build your own solution each
pleasing on the eye, but providing its users with a and every time you start a project.
basis of comparison to the other social networks. We’ll take you through the Bootstrap
Fundamentally Bootstrap is pure CSS, but framework, explaining how to use it and why it
as it’s built with LESS (a pre-processor that will revolutionise the way you create websites.
offers flexibility beyond what normal CSS can We’ll show you some excellent examples of
achieve) and has Sass support, there is a range of Bootstrap-powered websites, and point you
additional benefits over and above plain styles. in the direction of useful additional resources
The core CSS is broken into components, that will help you take full advantage of all the
allowing it to be easily managed and adapted. possibilities on offer. It’s particularly useful to
Each file in the set of Less source files deals understand why the framework is structured the
with one particular characteristic, so you have a way it is, so let’s start there.
82
Bootstrap Responsive design
Get started
Bootstrap works by providing a clean, uniform approach
to creating the most common user interfaces on the web.
Whether you’re creating a simple brochure website, or a
complex form, the same core components make up the
site design in terms of styles and content structure. By using
Bootstrap you can save time, pulling in ready-made controls,
layout elements and styles. This leaves more time to work
on aesthetics and testing.
The grid
A fundamental aspect of Bootstrap is the 100% fluid
The first thing you’ll need to get started with Bootstrap grid system built into the framework. There are four grid
is the framework itself. Visit getbootstrap.com to download options available, but the principle approach to working
the latest version of Bootstrap. All the media queries, grid with a grid remains the same. The responsive grid scales
sizing are all ready and setup included in this download. up to a maximum of 12 columns as the device or viewport
Once you’ve downloaded the framework, you simply increases. You can define how many columns each box
need to plug in the CSS and JavaScript files to create your should span, allowing you to simply and effectively align,
first Bootstrap page. without having to calculate widths manually.
83
Responsive design Bootstrap
Benefits
Modular
We take you through just a few of the benefits
of Bootstrap
easy to get clean cross-browser results without having to
The Bootstrap framework is modular, so you only need start from the ground up each time.
to call in the elements you need for your specific project,
making it relatively lightweight to deploy. Extensible
There are over a dozen jQuery plug-ins designed
Responsive specifically to work with Bootstrap, providing out-the-box
The grid system is fully responsive, allowing you to functionality for the likes of carousels, tooltips, dropdowns
design once and deploy your website across multiple and transitions. It is also easy to develop your own plugins.
device profiles, all without having to do any complex
mathematics or calculations. Pre-built components
Bootstrap includes a series of user-interface components
Quick to develop that you can instantly deploy, including drop-down
Bootstrap is built on standard CSS and JavaScript making navigation bars, auto-pagination, media objects, progress
it very quick to develop the accompanying HTML, and bars and many more.
84
Bootstrap Responsive design
1. mPurpose 4. JA Appolio
This free theme from http://bootstrapzero.com/ JA Appolio is a Joomla theme built on Bootstrap,
bootstrap-template/mpurpose is a fully responsive available free from http://www.joomlart.com/joomla/
multipurpose template. It includes over 30 sample templates/ja-appolio. A desirable portfolio template,
pages from portfolio layouts, business/agency layouts to it bundles with amazing features including parallax
carousel slider, eCommerce shopping layouts and more. design, blog ready, a selection of 5 colour schemes and 9
This is ideal for a web design agency site. bonus pages.
2. Fullby 5. DashGum
Free from http://www.marchettidesign.net/fullby/, Also free http://bootstrapzero.com/bootstrap-
Fullby is a Wordpress theme using Bootstrap. It features template/dashgum a 15 page dashboard panel or admin
a responsive video slider, animated shuffling of blog theme, this boost some unique interactive components
posts, animated widgets, and wide selection of colours including charts, tables, calendar notifications, to-do lists
to choose from. and more.
85
Responsive design Bootstrap
Among the key features of the Bootstrap framework is its It’s also extremely convenient to use some of the more
concept of components. These are re-usable user interface basic components, such as list groups, panels and wells, as
controls that cover the most common interactions, and these inherit the global style definitions automatically. This
range from drop-down menu systems all the way to means you can easily control the look and feel of common
modal pop-ups. content containers without having to explicitly define each
Components are implemented using a combination one individually.
of styles and scripts, and are typically initiated simply by Naturally, you can create your own additional
applying a specific set of classes to your markup. The components that you’ll be able to subsequently re-use in
documentation (available from getbootstrap.com/ future projects. The Bootstrap documentation walks you
components) provides some great examples for each of the through the process of integration, or you can use a third-
components that ship as part of the core Bootstrap build, party service such as Jetstrap (jetstrap.com/) to build your
but each of these is just the starting point. The idea is that own custom user experience elements and designs.
you will dress the component to suit your own website’s
layout and aesthetic treatment, altering or extending
functionality as you require, to provide a perfect fit for all of
your needs.
Better still, because the component system is entirely Customisation
modular, you’re not limited in any way to the twenty or
Components are little more than
so that come in the box; there are a raft of additional
HTML markup classified using a
components available on the web that extend the basic
combination of structure and classes.
functionality still further. Some of these are not much more
As a result, they’re incredibly flexible
than a jQuery plug-in, but tend to be designed around the
and infinitely customisable. If you
Bootstrap ecosystem, offering similar syntax and integration
want to change the look or the way to
to the standard set.
interact, you simply need to edit the
Although it’s often tempting to build your own solution
associated CSS and/or JavaScript.
to a particular user interaction requirement, by using off-the-
shelf components you can focus your time on enhancing
the all-important user experience, and rapidly prototype
your ideas without impacting negatively on time or cost.
86
Bootstrap Responsive design
5 Popular UI
Components
A collection of elements that can
be instantly added to a site.
3. Alerts
Useful when you’re trying to draw your user’s
attention to important information – either in
response to their input, or as a consequence of
something new or time-limited – alerts are an
extremely common call-out approach to highlighting
feedback. Bootstrap provides four styles, including a
dismissible alert.
1. Jumbotron
This component encapsulates a popular layout
technique: an oversized typographical box. Typically
such an area includes a call to action, so the Bootstrap
Jumbotron has a button built in to the design – which
4. Input groups
is, of course, easily customised.
Input groups make it easy to develop clean, validated
user forms that respond consistently. The core styling
is simple and follows the current trend for minimalist
aesthetics, you can also append or prepend text or
buttons either side of text based inputs.
87
Responsive design Bootstrap
Basic HTML
Download the framework
02 Bootstrap plugs straight in to your regular HTML
page, so start by creating a simple blank page that
88
Bootstrap Responsive design
A little bit
LESS.js
Add a Jumbotron
89
Responsive design Bootstrap
Grab a template
Replace the hero
01 The easiest way to start this project is to grab one
of the ready-made example templates on the
getbootstrap.com website. We’ve opted for the Jumbotron 02 We’re going to replace the Jumbotron hero panel
with a carousel. Visit the documentation for the
template because we can replace the Jumbotron with our Carousel plug-in, found within the JavaScript section of the
carousel. Copy the HTML source code, and paste it into a Bootstrap website, and copy the code example. We’ll paste
new page to get started. this in place of the Jumbotron in our template.
90
Bootstrap Responsive design
Responsive carousel
The carousel slideshow component comes fully responsive be sure that your images are wide enough to
encompass all common screen widths. This can create a big impact, especially on portfolio websites where
images are used to show off your work.
91
Responsive design Bootstrap
Resources Be inspired
Bootstrap is the underlying
Bootstrap has a lot of resources framework for some amazing
available on the web, check out five websites – take a look at two of the
of our favourites below best to get some inspiration for your
Bootstrap next project
getbootstrap.com
Straight from the source, the Bootstrap website
provides an off-the-shelf download of the framework,
a customisable download builder, and a full set of
documentation for the framework covering all the
standard plug-ins, components as well as the grid system.
This is also the place to get the latest official news
Bootstrap Google+
https://plus.google.com/communities/
110370020620457615447
This is the Google+ community group for Bootstrap, visit
here if you’d like to seek help from other users, or to learn
about the latest news. This group currently boast over
4000 active members. There are regular updates when
new templates, components and plugins are launched. Lexi Miller
Bootsnipp http://leximiller.com/
bootsnipp.com This clean, simplistic and gorgeous looking feminine
A handy resource site that gathers together HTML website sells fashionable athletic clothing. It takes
snippets, themes, components and plug-ins in a gallery advantage of the responsive native in the Bootstrap
that’s easy to browse. Users can contribute snippets, framework and utilises it as its own.
sharing their own work with the community for mutual
benefit, and the site also features a handy page of links to
other Bootstrap resources for quick reference
Start Bootstrap
http://startbootstrap.com/bootstrap-resources/
Kickstrap calls itself a ‘complete kit for making websites’,
building on top of Bootstrap with additional support for
libraries such as Raphael without the pain of manually
bringing together disparate resources. A useful resource
for sites that need to go further than basic Bootstrap
Bootswatch
bootswatch.com
Bootswatch is a simple theme site for Bootstrap, but rather
than focus on the complete end product, it provides a Entora
core set of styles that integrate beautifully with the basic http://entora.com/
Bootstrap components to create markedly different
aesthetic treatments. It’s limited in the range of themes it A beautiful entertainment source to follow your favour
offers, but many are worthy of forming the basis for your artists. This website takes advantage of the mobile first
own customisations. fluid grid system using the extra small grid option to
force grids to be horizontal at all times.
92
Bootstrap Responsive design
Now that you’ve got an overview of how Bootstrap works, work to clients. Keep in mind that your prototypes can go on
what makes up the library, and how to leverage the to form the basis of the final product too, so you’re
framework to build a website, you’re ready to start building saving time upfront as well as in the website or application
your sites using Bootstrap. build phase.
Your first step should always be to create a customised Once you’re confident, you may want to develop custom
download, rather than relying on the kitchen-sink approach functionality or components that simply aren’t covered by
of downloading everything. This will make your site leaner the default install of Bootstrap, or that work differently to
and more bandwidth-friendly, which your users will thank the standard behaviour. You don’t need a huge amount of
you for. Once you’ve got the framework, build your own technical knowledge or skill to be able to generate your own
theme – working on top of an existing template or theme if assets that you can go on to reuse in future projects. Similarly,
you’d like a quick start – and develop your content in situ. if you’re a front-end developer you may find that you want to
Bootstrap is particularly powerful for rapidly prototyping develop custom widgets and plug-ins that leverage jQuery.
user interfaces, making it an ideal solution for generating This process is very straightforward, and there’s a full set of
style tiles or non-functioning mockups when presenting documentation on the getbootstrap.com website.
Bootstrap 3
Since the release of version 3, lets look back comparing to the predecessor
and on advancement it has made.
The difference between Bootstrap 2 and Bootstrap 3 is as ‘red’, a more semantic naming scheme is used. The
that version 3 takes a mobile-first approach to ensure CSS has been tidied up too.
your designs is fully responsive on the get go. There are some structural changes to the way you
Under the hood the developers have focused on build your web apps, so the shift to version 3 from
trimming and rationalising the framework so that, for version 2 will require some HTML alterations, but the
example, rather than internally referring to an alert box fundamental approach remains the same.
93
Responsive design Build a custom Foundation template
Build a custom
Foundation template
Get started using Zurb’s Foundation framework to build a responsive template
that can be reused for any project
When starting a new responsive web design project, trying to custom develop your own framework
that includes a flexible grid system, media queries, typography, JavaScript media including video,
carousels, lightboxes and more can be exhausting. Not to mention the changing web arena, you’ll have
to rigorously maintain and update your framework to keep up to date with all the new features.
Using an open source framework like Foundation by Zurb helps to relieve the stress on developers.
This robust and flexible framework is well documented and has a host of ready components to reuse;
the best part is you can easily customise it, adding and removing functionality to suit your needs.
Foundation is built to be mobile first, so as soon as you start using this framework for your web project
it’s instantly responsive.
Through this tutorial we’ll touch upon some of Foundation’s core components and how to assemble
these to create your own custom template, which can be reused for any project.
94
Build a custom Foundation template Responsive design
Basic styles
<left>
Using the Top Bar plug-in you
can easily create functional
drop-down menus, the only real
work is styling it up
<below>
Incorporating a responsive
rotating slider with swipe- and
touch-enabled functionality is a
breeze using the Orbit plug-in
Option</a></li>
(this will only appear on a small Sub menu 007 </ul>
mobile screen). The top-bar class is 008 </li>
used for presentational purposes, the 009 </ul>
data-option stick_on will force the
navigation to stick to the top of the
06 Creating drop-down menus
can sometimes be overly
complex and tricky but Foundation
010 </section>
browser window.
makes the whole process very simple. Style the menu
001 <nav class=”top-bar” data-topbar Within the <nav> create a <section>
with the class top-bar-section.
002
data-
options=” sticky_on: large”>
<ul class=”title-area”>
Within this we create a <ul> and our
<li> items, making sure to add the
07 The beauty of an advanced
framework such as Foundation
is that it provides a lot of default
003 <li class=”name”> class has-dropdown to act as our styling for us, which means we can
004 <h1> <a
secondary menu. concentrate on structuring our page
href=”#”>Foundation
Custom Template</ and customising our styling a lot less.
001 <section class=”top-bar-section”>
a></h1> You will notice the menu will have
002 <ul class=”left”>
005 </li> its own custom styling already. We’ll
003 <li class=”has-
006 <li class=”toggle-
dropdown”> just add a drop shadow with some
topbar menu-
004 <a class=”active” browser vendor prefixes.
icon”><a
href=”#”>
href=”#”><span>Menu 001 .top-bar {
Main Item 1</a>
</span></a></li> 002 -webkit-box-shadow: 0px 3px
005 <ul class=”dropdown”>
007 </ul> 7px 0px rgba
006 <li><a
008 </nav> (50, 50, 50, 0.75);
href=”#”>Dropdown
96
Build a custom Foundation template Responsive design
003 -moz-box-shadow: 0px 3px 006 time_speed: 1000, 002 <div class=”large-6
7px 0px rgba 007 pause_on_hover:true, columns”>
(50, 50, 50, 0.75); 008 bullets: false, 003 <div class=”flex-
004 box-shadow: 0px 3px 009 } video”>
7px 0px rgba 010 }); 004 <iframe
(50, 50, 50, 0.75); 011 </script> width=”560” height=”315”
005 } src=”//www.youtube.com/embed/_
ejeqxRdGwk”frameborder=”0”
Basic content allowfullscreen></iframe>
Orbit slider plug-in 005 </div>
extremely simple when we features, making it easy to create multi- Panel component
use the Orbit slider plug-in. First we’ll device layouts. The row class is used
wrap the code within a row class, to hold all the columns, defining a grid
followed by a large-12 columns grid
to lay out our carousel. Apply a orbit-
column of 12 indicates the number of
columns we need in a row. Below is
12 Let’s have some accompanying
content next to our video. We’ll
use another six-column grid and to
container class and a data- orbit data- a basic structure of content using the
add components that help outline
attribute using a <li> item to separate grid system.
sections on a page we can use the
each slide.
001 <div class=”row main-content”> panel component. All you have to
001 <div class=”row”> 002 <div class=”large-12 do is create a wrapping <div> called
002 <div class=”large-12 columns”> columns”> panel encasing your content and
003 <ul class=”orbit-container” 003 <h1>Our latest work</h1> Foundation will automatically apply
data-orbit> 004 <p>Lorem ipsum….</p> a border and background colour to
004 <li> 005 <img src=”img/photo.png” this panel.
005 <img src=”img/ alt=”” />
slides/slide-1.jpg” 006 </div> 001 <div class=”large-6 columns”>
alt=”slider 1” /> 007 </div> 002 <div class=”panel”>
006 <div class=”orbit- 003 <p>Lorem ipsum ….</p>
007
caption”>
Text to go here
Make a child theme 004 </div>
005 </div>
008 </div>
009
010
011
</li>
</ul>
</div>
11 Adding a video is extremely
easy. Foundation will
automatically help you to scale your
Lightbox gallery
012 </div> video from an intrinsic ratio, so you can
guarantee it can be properly scaled 13 To build a lightbox gallery of
photos to slide through with
Orbit JavaScript and viewed on any device. Simply add a variable height, we can use the
the class flex-video as a containing Clearing plug-in. Again, wrap the code
<div> around your video. in a row class with the grid columns,
09 Before the ending </
body> tag there is an initial
Foundation JavaScript, simply used
001 <div class=”row”>
open a <ul> and apply a class of
clearing-thumbs and a data-attribute
to call all plug-ins on the page. Using
this we can customise the plug-in
initialisation. We can configure the
options for the Orbit plug-in, so let’s “Foundation contains a whole host of
change the default slide effect to a
fade animation and change the speed helpful components and the best place
at which it rotates.
to read and understand all this is by
001
002
<script>
$(document).foundation({ looking at their detailed documentation
003 orbit: {
004
005
animation: ‘fade’,
animation_speed:500,
at foundation.zurb.com/docs/index.html.”
97
Responsive design Build a custom Foundation template
001 .gallery {
of data-clearing. Each <li> item will act
as a separate photo slide.
002 padding: 20px 0; Error message
003 background-color: #f2f2f2;
004 }
001
002
<div class=”row gallery”>
<div class=”large-12
columns”>
005
006
.clearing-thumbs li {
margin: 0 20px 20px 0;
17 If you do not fill out the input
field or input the incorrect data
this will return an error. However this
007 }
003 <h2>Gallery</h2> does not display an error message to
008 .clearing-thumbs li:first-child
004 <p>View our latest
{ the user, which is not helpful. To apply
photos</p>
009 margin-left: 10px; an error message, add a <small> tag
005 <hr />
010 } with the class error and place your
006 <ul class=”clearing-
thumbs”data-clearing> error message within this.
007 <li> Common styles
008 <a href=”img/ 001 <small class=”error”>Please
photo.jpg”> enter your name</small>
009 <img src=”img/
photo.jpg”
15 To create a uniformed look and
give all our elements equal
spacing, we’ll style the main content, Email input
alt=”” data-caption=”Text to go
here” /> gallery and the subsequent contact
010
011
012
</a>
</li>
</ul>
form (in the following step) with some
margin and make the content aligned
centre. If you ever use Sass with
18 It’s the same markup again to
set the email input field, use
the input type attribute and place
013 </div> Foundation, you can always use the @ the pattern name within this to help
014 </div> validate the input field. To set an error
extend for this case.
014 </div>
message within the same <div>, add
001 .main-content, .gallery, the <small> tag with the class error.
Gallery styles .contact-us {
002 margin-bottom: 30px; 001 <div class=“email-field”>
003 text-align: center; 002 <label>Email:
and bottom padding. Each <li> item Contact form ”[email protected]” required
/>
will have a bottom and right margin 004 </label>
so they’re equally separated. Using the
CSS pseudo class first-child we can 16 Creating user-friendly and
HTML5 validation-ready forms
is wonderfully simple in Foundation.
005
006
<small class=”error”>
Please enter your email</small>
</div>
give the first <li> item a margin-left.
98
Build a custom Foundation template Responsive design
gradient(180deg, rgb
Message field 12 columns grid within our content.
(43, 43, 43) 30%, rgb(29, 29,
We will then separate the footer to 29) 70%);
two equal halves using two children 007 }
19 A contact form would not be
complete without a message
field. Similarly to our input fields we
large-6 column grids.
99
Responsive design Build a responsive WordPress theme
Build a responsive
WordPress theme
As the most advanced responsive framework available, Zurb’s Foundation is
ideal for your latest WordPress project
Previously to incorporate Zurb’s Foundation framework into WordPress you had to manually link the
necessary JavaScript and CSS using the WordPress functions ‘wp_enqueue_script’ and w’p_enqueue_
style’. But now, thanks to Zurb and the popularity of WordPress, Zurb has provided a starter-theme
called FoundationPress, which you can download directly from its GitHub page to start building your
own WordPress theme with the Foundation framework.
The purpose of this ultimate starter theme is to act as a springboard; it comes packed with useful
re-useable components, a 12-column responsive grid, JavaScript functions and much more. This starter
theme contains all the necessary design elements, including the JavaScript and CSS libraries.
Still, FoundationPress is not an all-in-one WordPress theme with plugins, shortcodes, custom
options or custom templates – it is only to be used as a starting point. Luckily it has done most of the
hard work for us including setting up widgets, navigations, displaying blog posts and general clean-up
of WordPress.
100
Build a responsive WordPress theme Responsive design
Start building responsive WordPress themes using Zurb’s own advance You can download Zurb’s Foundation WordPress starter theme,
Foundation framework starter theme, conveniently called FoundationPress, with ease over on GitHub
FoundationPress
101
Responsive design Build a responsive WordPress theme
<top> <bottom>
In WordPress, activate FoundationPress starter FoundationPress allows you to order menus to be
theme. This theme includes all the Foundation on the left or right side of the menu and enable
framework library for mobiles
006
0%, #007295 100%);
background: -webkit-
06 Currently in our widgets list,
the search form is located in
the sidebar. In WordPress Widgets
default grid layout to use the large grid
system as well as setting some custom
gradient(radial, center classes to be referenced in our CSS.
center, 0px, center center, we can disable the search widget.
100%, color-stop(0%,#00b3d3), Now inside our ‘head.php’ at the 001 <div class=“row”>
color-stop (100%,#007295)); very bottom, paste in the following 002 <?php do_action
007 background: -webkit-radial- function, which will print out the (‘foundationPress_
gradient (center, ellipse search form. We’re going to place our searchform_top’); ?>
cover, #00b3d3 0%,#007295 100%); search form just below the header of 003 <div class=“large-8 columns
008 } searchbox”>
our website.
009 .main-head h1 { 004 <input type=“text” value=“”
010 text-align: center; name=“s”id=“s”placeholder
001 <?php get_search_form(); ?>
011 font-weight: 900; =”<?php esc_attr_e(‘Search’,
012 text-transform: uppercase; ‘FoundationPress’);?>”>
013 letter-spacing: 10px; Customise search 005 </div>
014 text-shadow: 1px 1px 2px rgba 006 <?php do_
(50, 50, 50, 0.59); action(‘foundationPress_
015
016
font-size: 2.5rem;
color: #fff;}
07 With the get search form
function added in our ‘header.
php’ we can now structure this search
searchform_before_search_
button’); ?>
102
Build a responsive WordPress theme Responsive design
009
?>” class=”prefix button”>
</div>
009 <p>Posted on <?php
the_time(‘F jS, Y
’); ?> in <?php the_
11 With our blog posts neatly
organised in a row of threes,
our search field and search button are
category(‘, ‘);
Modify index.php ?></p>
not quite aligned with the rest of the
design. Let’s fix this by adding some
010 <p class=”byline
padding. With a mobile-first approach,
08 The ‘index.php’ is the main
template in WordPress
theming hierarchy. We’re going to
author”>Written by
<?php the_author_posts_
link(); ?>
Foundation takes care of the
responsive nature – it’s unnecessary to
modify it and remove some of the </p> add styles for mobile or tablet devices.
011 <a href=”<?php the_
grid components and place them in
permalink(); ?>” 001 .searchbox, .searchbutton {
‘content.php’ instead. Remove the class=”button”>Read 002 padding: 0 15px;
<div> row and grid classes just below more</a> 003 }
the ‘get_header’ function and replace 012 </div> 004
it with the code below. Finally, migrate
the <?php get_sidebar(); ?> just above Style the blog Move the sidebar
the ‘get_footer’ function.
001
002
<?php get_header(); ?>
<div class=”row” data-equalizer> 10 With our blog post structure
set up in a grid column in a set
of threes, we’ll now implement some
12 Rather than having our sidebar
situated on the right-hand
column, we will position it directly
simple styling to this homepage. Back below all the blog posts and just
Blog post in our ‘style.css’, we’ll add some box above the footer. Inside the ‘sidebar.
shadow so the panels don’t look so php’ we’re going to use Foundation’s
003
data-equalizer-watch>
<header>
“Working with Sass provides greater
004 <h2><a href=”<?php
the_permalink();
flexibility and control over this theme. All
?>”><?php the_title();
?></a></h2>
Sass variables are located in scss/config/_
005
006
</header>
<div class=”entry-content”> variables.scss and your site structure
007 <figure><a href=”<?php
the_permalink
(); ?>”><?php if (
within scss/site/_structure. ”
103
Responsive design Build a responsive WordPress theme
<top left>
Easily set up and use shortcodes in your
site to take advantage of Foundation’s
library of components
<bottom left>
Using WordPress shortcodes, we were
able to add Foundation’s alert box
components throughout the site
104
Build a responsive WordPress theme Responsive design
105
Responsive design Make a responsive menu for a retina screen
Make a responsive
menu for a retina screen
Make sure your menu is both responsive and ready for
retina screens by using custom fonts instead of images
Designing the navigation element for your website in this age of mobile devices and differing screen
widths can be a real pain in the mouse. Balancing usability with aesthetic credibility is the challenge that
responsive design now presents to all designers. There are a wide variety of solutions and techniques
available to solve the issue, from fixed drop-down menus to side-sliding variations. The problem is that,
while these solutions all solve the problem of maintaining functionality at different screen widths, they
can sometimes lacking visual impact.
These days it’s nice to see a menu that remembers to look good, too. Longer, scrolling pages are
reducing the number of menu elements some sites need to present, and those sites, in particular, can
afford to be a little more adventurous with how they deliver the navigation. So it’s time to give the
responsive menu a much needed paint job and raise it above the purely functional. This tutorial will
demonstrate how to create a responsive menu that is both eminently usable and visually striking. And
to keep it retina friendly, we’ll be using a custom-made icon font rather than images.
As more and more screen sizes flood into the market, it pays to keep your responsive elements as simple as possible to avoid meeting a width they can’t
deal with. Having three breakpoints, roughly representing PC, tablet and smartphone, is a tried and trusted approach to this problem
106
Make a responsive menu for a retina screen Responsive design
uniF4F1,.icon-skull,.icon-uniF539,. 010 }
Choose your icons icon-rocket,.icon-menu { 011 header {
012 font-family: 'icomoon'; 012 text-align: center;
013 speak: none; 013 font-size: 16px;
01 In order to create the custom
icon font, we’ll be using the
excellent IcoMoon tools at icomoon.
014
015
font-style: normal;
font-weight: normal;
014 background:
rgba(255,255,255,0.6); 015 }
016 font-variant: normal; 015 header h1 {
io/app/#/select. You have a choice 017 text-transform: none; 016 font-family: 'Hammersmith
here of creating your own icons as 018 line-height: 1; One', sans- serif;
vector images to import into the font 019 -webkit-font-smoothing: 017 font-size: 75px;
creator or choose from the extensive antialiased; 018 line-height: 0.8;
selection already available. We’ll 020 } 019 margin: 0;
choose ours from the library as they 021 .icon-happy:before {content: 020 font-weight: 300;
"\e603";}022 .icon-loved:before 021 color:#3f3782;
have exactly what we need.
{content: "\e61c";} 022 }
Create
a custom font 023 .icon-uniF4F1:before {content:
"\e613";}
023 .movie {
024 font-size:102px;
024 .icon-skull:before {content: "\ 025 color:#e63c2b;
107
Responsive design Make a responsive menu for a retina screen
As more and more screen sizes flood into the market, it pays to keep your responsive elements as simple as possible to avoid meeting a width they can’t
deal with. Having three breakpoints, roughly representing PC, tablet and smartphone, is a tried and trusted approach to this problem
.5s; 007 }
styles are completed, so make sure
004 -o-transition: background 008
.5s;
you remember to close the media
005 -ms-transition: background .5s; query here.
006 transition: background .5s; Second media query
007 } 001 .nav li:hover {
002 background:rgba(0,0,0,0.9);
008 }
11 Our second media query
targets screen widths between
003
.5s;
-moz-transition: background
Add the background 520px and 799px, which covers 004 -o-transition: background
tablet screens and some larger .5s;
smartphones at landscape. Our layout 005 -ms-transition: background
Rather than having to adapt the layout per screen width, we’ll use each breakpoint as an opportunity for redesigning
109
Responsive design Make a responsive menu for a retina screen
Background changes
110
Make a responsive menu for a retina screen Responsive design
If you look across a range of interests you’ll often find some mixed-up priorities. In photography, many
beginners focus on the best camera body they can afford whereas experienced photographers know
it’s the quality of the lens that’s all-important. Some golfers will spend hours at the driving range but
completely neglect their short game.
With responsive web design, the temptation can be to concentrate on the overall layout, and which
divs do what as the viewpoint changes, but what about your text? People have arrived at your site to
read what you have to say and if they don’t find it easy or enjoyable they simply won’t stay. If you want
your website to be responsive and effective then you really need to know a little about responsive
typography. As with many other web design disciplines you’ll have to deal with browser compatibility
issues, and as you venture further, you’ll appreciate the diversity of the issues you need to consider and
the refinements that are possible. You can achieve a great deal with CSS only but there are also a few
handy jQuery plugins too. It’s time to focus on the typography.
112
Techniques for creating responsive typography Responsive design
The measure of it one column of text you’ll need to typically use smaller rem values. You
allow plenty of negative space around will also tend to use much narrower
the text block to ensure a good user margins to enable you to make the
01 For optimum readability your
line length (or measure) should
be 45-75 characters. Within sensible
experience. The img element shows
an example of using rem units to set a
most of the available screen space.
001 /* ===== == = 37.5em (600px) =
relative size to the bottom margin. == ===== */
limits, select your font and the width
it is to occupy. You can then set the 002 @media only screen and
001 #page-wrap { (min-width: 37.5em) {
font-size of your body text. In this 002 width: 60%; 003 html {font-size: 16px;}
case the size is set to 18px in the root 003 margin: 100px auto; 004 #page-wrap { width: 75%;
element ‘html’. 004 } margin: 2rem
005 img { auto; }
001 @import url(http://fonts. 006 max-width: 90%; 005 }
googleapis.com/ 007 margin-bottom: 2rem; 006 /* ===== == = 48em (768px) = ==
css?family=Droid+Serif|Quando); 008 box-shadow: 0 0 8px ===== */
002 * { #333333; 007 @media only screen and (min-width
003 margin: 0; 009 } : 48em) {
004 padding: 0; 010 008 html {font-size: 18px;}
005 } 009 #page-wrap { width: 65%;
006 html { font-size: 18px;
007 font-family: ‘Droid Serif’,
Breakpoints margin: 2.5rem
auto; }
serif; 010 }
008
009
010 }
background-color: #e7bb4a;
color: #333; 04 Decide on the breakpoints
to use for your site. Using
ems means your breakpoints will be Large and bold
011 respected even if the user changes
Keep it relative
the text zoom in their browser. At
each breakpoint you have the
opportunity to tweak the factors that
06 At larger sizes you’ll really want
to make use of impressively
sized headings and large margins to
will affect the readability of the text at give each element its own space.
02 Using rem units (as in h2 here)
enables the relative size of the
element to be fixed according to the
that screen size. 001 /* ===== == = 56.25em (900px) =
== ===== */
001 /* ===== == = 20em (320px) = ==
root element. You might have several ===== */
002 @media only screen and (min-width
dozen rem-sized elements in your :
002 @media only screen and (min-width
document and simply changing the 56.25em) {
: 20em) {
003 html {font-size: 20px;}
font-size in your html element will 003 html {font-size: 12px;}
004 #page-wrap { width: 60%;
automatically change their size. 004 #page-wrap { width: 85%; margin:
margin: 3rem
1rem
auto; }
auto; }
001 h2 { font-size: 2.8rem; 005 }
005 }
002 margin-bottom: 15px; 006 /* ===== == = 68.75em (1100px) =
006 /* ===== == = 30em (480px) = ==
003 font-family: ‘Quando’, serif; == ===== */
===== */
004 color: #a2422a; 007 @media only screen and (min-width
007 @media only screen and (min-width
005 } :
: 30em) {
006 p { 68.75em) {
008 html {font-size: 14px;}
007 line-height: 1.45; 008 html {font-size: 22px;}
009 #page-wrap { width: 80%;
008 margin-bottom: 20px; 009 #page-wrap { width: 55%;
margin:
009 } margin: 3.5rem
1.5rem auto; }
010 auto; }
010 }
010 }
011 /* ===== == = 81.25em (1300px) =
Manage your widths Subtle and small == ===== */
012 @media only screen and (min-width
113
Responsive design Techniques for creating responsive typography
Headline text is the most noticable text on a page and any good headline should scale down so it is easy to read on all screens.
FitText.js is a jQuery plugin that does exactly what it says, make text fit, whatever the screen size
114
Techniques for creating responsive typography Responsive design
008 #page-wrap { width: 65%; margin: responsive text makes use of viewport
007 fontRatio : 45
008 }); units. Each unit is equivalent to 1% of
009 </script> 2.5em auto; }} the viewport width or height. Browser
010 009 @media only screen and support is currently lower than for rem
(min-width : 56.25em) { units but in exchange you get fully
010 #page-wrap { width: 60%; margin: fluid text and could probably make do
Font ratio with only two media queries to avoid
3em auto; }}
inappropriately small or large text.
10 Each font is different and the
fontRatio variable enables you
to tweak the font size to achieve your
001 h1 {
R for root 002 font-size: 5.9vw;
desired result. Increase the value to 003 }
make the font smaller, and vice versa. 004 h2 {
It should go without saying that you
need to check how your page looks at
12 By default, Flowtype is applied
to the body of the page.
However, as the heading is set using
005
006
007
font-size: 3.0vh;
}
p {
different widths. rem units, the heading will not be 008 font-size: 2vmin;
re-sized. There are two ways round 009 }
Media queries again this. First you can set Flowtype to 010
apply to the root element by changing
007
115
Responsive design Techniques for creating responsive typography
116
Techniques for creating responsive typography Responsive design
FlowType.js
Simple Focus is the name of the agency that developed this
plugin which is apt here as the code is both simple and focused.
001 (function($) {
002 $.fn.flowtype = function(options) {
Variables are set here, but can
be overridden when the plugin 003 // Establish default settings/variables
is called in the HTML 004 // ====================================
005 var settings = $.extend({
006 maximum : 9999,
007 minimum : 1,
008 maxFont : 9999,
009 minFont : 1,
010 fontRatio : 35
011 }, options),
Create a HTML5
responsive video player
Discover how to create a fully responsive HTML5 video player that
features custom control icons to fit your designs
Everyone knows that video is the best way to keep your audience engaged, however, you now want to
add some of that video goodness onto your fancy responsive website. You scurry off to YouTube and
grab that all-important embed code, lovingly paste it in, only to find that it looks terrible on tablets and
phones. Not only that but the controls are all the same boring icons. Time for a change, in the form of
an HTML5 video player that adapts to your responsive site and fits in with your existing UI with some
custom controls.
We’ll be basing this tutorial around Bootstrap, for a couple of reasons. The first being that it’s the
most popular responsive framework out there, so many people will already be using it; the second
reason is that it comes bundled with Glyphicons, which we’ll use to create player controls. You can, of
course, create your icons using standard PNG images if you so wish.
Using this technique we will end up with a video that looks consistent, as the standard HTML5
video player is rendered completely different across different browsers using the browsers built-in
controls, here we make it look identical across all platforms, and respond to smaller devices.
118
Create a HTML5 responsive video player Responsive design
code underneath the previous step any format you wish – they even have support the
above the closing </body> tag. a 4K and 3D version as well as the video tag.
entire source used to create it. 004 </video>
</div>
Embed video 06 Depending on which browser
and operating system you are
using, the previous step may not have
007
008
<div class=”col-md-6”>
<h2>Right Col</h2>
05 Now we have our footage
we’re going to embed it into
the jumbotron using the standard
shown any video at all. If this is the
case you may need to add the OGG
009 <p>Donec id […] dui.</ version of the video into your code as
p> HTML5 markup. Add the following
well. Grab the OGG file from the video
010 </div> code within the jumbotron <div>,
download site and add the following
011 </div> replacing the <!-- Begin Video
line of code.
012 </div> content --> comment. Be sure to look
013 at the output in different browsers 001 <source src=”big_buck_
to see how the video controls are bunny_1080p.ogg”
Obtain footage rendered differently. type=”video/ogg”>
002
001 <video width=”320”
002
controls>
<source src=”big_buck_
Getting responsive
using a completely open source bunny_1080p_
short animation created by Blender
Foundation, ‘Big Buck Bunny’. mp4”>
h264.mp4” type=”video/
07 Now it’s time to make use of
that large jumbotron area and
fill it up with our video. Adjust your
003 Your browser does not
Download it from the link below in video tag height and width to the
By adding in a poster
image, we can display
a title screen that will
disappear when the
user presses Play
119
Responsive design Create a HTML5 responsive video player
following, to stretch the video across presented with a black video screen. actually play the video.
the jumbotron container. The video Until you hover over it, it’s not very
will adjust its height accordingly, so the 001 <video width=”100%”
obvious that it’s a video at all. There poster=”poster.jpg”>
aspect ratio is maintained correctly. are two ways around this, the first is
to set the video to autoplay, or we
001 <video width=”100%” controls>
can add the following code to add an Get video elements
intro slide.
Remove spacing 001 <video width=”100%” controls
poster=”poster.jpg”> 11 We will be using jQuery in
order to add controls back into
our player, simply because Bootstrap
08 Our jumbotron features
grey padding around the
video – let’s get rid of that to make Removing controls
needs it as well. Add the following
code block to the bottom of your
our video fill the entire space. Add a page, just above the closing </body>
CSS block above your video tag with
the following code within it. This will 10 Now we need to remove
the standard HTML5 video
player controls. This is easily done by
tag. This will cast the video element
onto a variable called ‘videoPlayer’ for
override the default Bootstrap CSS, but use later on.
there is no need for !important tags. updating the video tag, removing the
controls element, as per the below. 001 <script>
001 <style type=”text/css”> 002 $( document ).ready(function()
Keep in mind that while we’re coding
002 .jumbotron { {
the new controls we will be unable to
003 padding: 0;
004 margin-bottom: 0;
005 }
006 </style> “This will cast the video element
The poster element
onto a variable called ‘videoPlayer’ for
use later on”
09 You’ll notice when we
first load the page you’re
120
Create a HTML5 responsive video player Responsive design
volume-up”>
class=”glyphicon glyphicon-
</span></a>
15 Now we can play the video,
we can switch the Play control
to a Pause when it is active. We’ll do
The controls 007 <a href=”#” this via an ‘if’ statement that updates
class=”btnFullscreen”>
the button class, replacing the Play
13 Now it’s time to add the
controls back in, or at least
the HTML framework that will power
glyphicon-
<span class=”glyphicon
fullscreen”></span></a>
glyphicon with the Pause icon. The ‘if’
statement will also resume playback
them. This block of HTML adds all the 008 </div> and switch the icon back. Replace the
121
Responsive design Create a HTML5 responsive video player
previous step with the below. current time and the total time. Add following code will round that number
the following code block underneath up to the nearest second. You can
001 $(‘.btnPlay’).click(function() {
the previous step within your extend this functionality to display
002 if(videoPlayer[0].paused)
{ document ready script block. hours, minutes and seconds as well.
003 videoPlayer[0].play(); 001 $(‘.current’).text(Math.round
001 videoPlayer.on(‘timeupdate’,
004 $(‘.glyphicon-play’). (videoPlayer[0].currentTime));
function() {
attr(‘class’,
002 $(‘.current’).
‘glyphicon glyphicon-
text(videoPlayer[0].
pause’);
currentTime);
Total time
005 }
003 });
006 else {
007
008
videoPlayer[0].pause();
$(‘.glyphicon-pause’).
Less accuracy 18 The next thing to do is to get
the total duration of the video
and display this next to our current
attr(‘class’,
play’);
009
‘glyphicon glyphicon-
}
17 You may have noticed that our
time includes milliseconds as
well as seconds; this is probably a little
time. Add this code underneath the
previous step to hook up the span in
our control <div>. Again; you will
010 return false; bit too accurate for most situations. need to round the number to get rid
011 }) Altering the previous step to the of the milliseconds.
122
Create a HTML5 responsive video player Responsive design
005
006
off’);
} else {
videoPlayer[0].muted =
21 Now we’ll make our controls’
appearance look a bit better by
adding the following code within our
014
015
016
}
color: #999;
.glyphicon:hover {
false;
CSS block from Step 8. When dealing 017 color: #555;
007 $(‘.glyphicon-volume- 018 }
with floating elements, don’t forget
off’).attr(‘ 019
to add a clear underneath to prevent
123
Resources Essential web design resources
Get free hi-res images for projects Search and find inspiration with Niice
Test out web fonts and typography Get thousands of free vector icons
124
Essential web design resources Resources
Create 3D with only CSS A responsive framework to help build sites quickly
Quickly create the perfect colour palette Get tools to test with Internet Explorer
126
Essential web design tools Resources
127
of al
r
al ci
fe
tri Spe
Enjoyed
this book?
Exclusive offer for new
Try
3 issues
for just
£5 *
* This offer entitles new UK direct debit subscribers to receive their first three issues for £5. After these issues,
subscribers will then pay £25.15 every six issues. Subscribers can cancel this subscription at any time. New
subscriptions will start from the next available issue. Offer code ZGGZIN must be quoted to receive this special
subscriptions price. Direct debit guarantee available on request.
** This is a US subscription offer. The USA issue rate is based on an annual subscription price of £65 for 13 issues,
which is equivalent to approx $102 at the time of writing compared with the newsstand price of $194.87 for 13 issues
($14.99 per issue). Your subscription will start from the next available issue.
128
Uncover the secrets
of web design
Practical projects
Every issue is packed with step-by-step tutorials for
Flash, Dreamweaver, Photoshop and more
In-depth features
About Discover the latest hot topics in the industry
the Join the community
mag Get involved. Visit the website, submit a portfolio and
follow Web Designer on Twitter
subscribers to…
TM
facebook.com/ImagineBookazines twitter.com/Books_Imagine
HTML5 & CSS3 The Complete Manual
The essential handbook for web designers
Terminology guides
With all the key terms in one place, understand
the jargon of web design