In this responsive web design tutorial we will create an awesome responsive HTML5 website starting from scratch. I tried to include as many different features as possible, so we will be dealing with a jQuery slider, CSS3 transitions and animations, CSS Media Queries and so on. This part of the tutorial will show you the HTML structure and the required scripts in a step by step tutorial. The second part will then show you how to style it using CSS3 features to create this stunning HTML5 cross-browser responsive website.
Please note that this tutorial is made for people who already have an intermediate knowledge level. Some parts of the tutorial will not be described in detail as it is assumed that you know how to e.g. include a CSS file. If you have any questions you can always use the comment section and I will try to help you.
First of all let´s have a look at the basic structure of our website. Click on the image on the right side to see how our website will be arranged. I recommend to always draw a layout before starting to build a website. Having this overview of our structure will make it a lot easier to create the page.
Creating the head – Doctype and Meta Tags
Let´s begin by defining the HTML5 doctype and creating our head section with the required scripts and CSS files. The doctype declaration in HTML5 is fairly easy to remember compared to previous HTML/XHTML versions.
In our head section let´s set the charset to UTF-8 which is also easier now in HTML5.
As we would like to create a responsive design which should work on all kind of devices and screen resolutions we need to add the viewport meta tag which defines how the website should be displayed on a device. We set the width to device-width and the initial scale to 1.0. What this does is set the width of the viewport to the width of the device and set the initial zoom level to 1.0. That way the page content will be displayed 1:1, an image with a size of 350px on a screen with 350px width would fill out the whole screen width.
Note that there are multiple different opinions about using initial-scale and width=device-width. Some people say not to use initial-scale at all as it might lead to incorrect behavior in iOS. In some cases a zoom bug occurs when rotating the device from portrait to landscape. As a result users have to manually zoom the page back out. Removing the property initial-scale might sometimes fix that bug. If it does not there is a script which disables the user’s ability to scale the page allowing the orientation change to occur properly.
However there are also people saying only to use initial-scale and not width=device-width. Raphael Goetter for example wrote in his blog post:
initial-scale=1.0 fits the viewport to the dimensions of the device (device-width and device-height values), which is a good idea because the size of the viewport fits the dimensions of the device regardless of its orientation.width=device-width size the viewport to always corresponds to the (fixed value) width of the device, and thus is distorted in landscape orientation because que right value should be “device-height” not “device-width” in landscape (and it’s worse on iPhone5 whose device-height value is 568px, compared to its 320px device-width).Therefore, I would rather recommend to use initial-scale alone, not associated width=device-width. Because the combination of the two is problematic, and moreover I think than even only width=device-width is problematic.
In conclustion there is no general instruction on which properties to use. You might first try to include both initial-scale and device-width. If that leads to problems in iOS or Android try removing either one of the properties. In case that still does not solve your problems try using the script I mentioned above until your responsive design is displayed correctly on all devices.
Creating the head – CSS files
In our website we will use four different CSS files. The first stylesheet is called reset.css. What it does is resetting the styling of all HTML elements so that we can start to build our own styling from scratch without having to worry about cross-browser differences. For this tutorial I used Eric Meyer’s “Reset CSS” 2.0, which you can find here.
The second stylesheet is called style.css and contains all our styling. If you want you can also divide this CSS file into two and separate the basic layout styling from the rest of the stylesheet.
If you look at the preview of our website and click on one of the small images in the main content section you will see that a larger version of the image will show up on top of the page. The script we use to achieve this is called Lightbox2 and is an easy way to overlay images on top of the current page. For this tutorial you will need to download Lightbox2 and include the CSS file “lightbox.css”.
The last stylesheet (Google WebFonts) will let us use the fonts Open Sans and Baumans. To find fonts and include them into your project visit Google Web Fonts.
Please note that when using multiple CSS and Javascript files the amount of HTTP requests increases which results in longer page loading time. For the live version of your website you could combine all CSS and Javascript files into a single one. If you know that you are not going to change your CSS code again then this would be a good solution. If you however want to be able to change your CSS and JS files from time to time I would recommend not to combine the files manually as this will probably make things confusing and more difficult to look through. You might rather want to use a minifier script which automatically combines, minifies and caches all your CSS and Javascript files into one single file. One of these scripts is called minify.js and can be found here.
Creating the head – Javascript / jQuery files
Now that we have included the CSS files let´s add all the required scripts. As we are using HTML5 and CSS3 features we need several scripts to make the features visible in all browsers. The first script we will be using is Modernizr.js, a feature detection library for HTML5 and CSS3. It let´s you easily detect whether a browser supports a specific feature or not. Modernizr.js also comes with html5shiv which enables HTML5 elements in Internet Explorer. To download Modernizr.js click here and click on the large “Build” button in the top right corner. Then click on “Download” next to “Build”.
The second script we need is Respond.js, a script which enables responsive design in Internet Explorer and other browsers which don´t support CSS Media Queries. Click here to download it from GitHub.
To be able to use i.e. lightbox.js we also need to include the jQuery library. The best way to do this is by letting Google host your jQuery file and use a fallback in case the Google jQuery file fails to load.
For Lightbox2 we need to include the lightbox.js located inside the js folder in the lightbox directory.
In this tutorial we will be using CSS3 features which require the use of different prefixes to work in all browsers. In order not to have to manually define the different prefixes each time we are using a CSS3 feature we will include the script Prefix Free, which automatically creates the required prefixes and let´s us write the unprefixed CSS properties. You can download the script from here.
The last script we will need is for the responsive Image Slider SlideJS. You can download the Plug-In from here and include the “jquery.slides.min.js” into your “js” folder.
Your file should now look like this. Note that in the course of this tutorial we will add further code to our head section.
Creating the body – Introduction
HTML5 offers several new elements which help us create more structured and accessible web pages. One of the main advantages of HTML5 is the possibility to structurize your web page and tell screen readers or search engine bots what is on a page which helps them to read only the parts they want.
Before we start coding let´s first have a look at the most important new sectioning elements in HTML5.
The new section element defines a part of a website with related content. It should not be used as a generic container element or for pure styling purposes. In that case rather use a simple div.
An article defines an independent piece of content which should be able to stand alone and still make sense.
A header defines a header for a document or a section.
A footer is used for defining the footer of a document or a section.
A nav defines a set of navigation links which should be the main navigation of your website.
An aside defines a section with secondary content. If an aside is placed within an article the content should be related to that specific article. If it is placed outside an article the content should be related to the site as whole.
Each of the sectioning elements in HTML5 should almost in any case contain a heading. By giving each section a specific heading you are creating a new section in the HTML5 outline. This is important as a proper outline does not only improve accessibility but is also good for SEO. To create a correct HTML5 outline you can use the Outliner Tool. In case you see an “Untitled Section” which corresponds to a section element in your HTML code you might want to specify a heading for the section. For further information on the document outlining algorithm be sure to check out Derek Johnson´s blog post.
If you have a look at the website we will be creating you will probably think: “Didn´t he just say that we need a heading for each sectioning element? I don´t see any heading for the header, the navigation, the footer or some of the sections.”. Obviously displaying a heading for each of the sectioning elements does not really make any sense.
On the other hand we need to define headings for every section to create a proper outline. Not using sections in our document at all would somehow destroy the whole purpose of a HTML5 structured document.
A solution for this is to add headings for each section into your HTML code and then hide them with CSS. You should not hide them with display:none though as this would also remove them from the outline. Rather use the CSS property clip to hide the headings which is also the best way not to get banned by search engines for hiding content. If you would like to read more about it check out this answer.
Creating the body – Building the website structure
Let´s start creating the HTML5 elements on the basis of our layout overview (click here to open the structure image in a second tab so you can switch between tabs while coding).
The first thing we need is a header. The header will include our navigation and our logo. Inside theheader we put the main heading h1 and a paragraph. The main heading could be your website´s name or logo and the paragraph a motto or phrase describing the website. Depending on whether the subheading contains the main keywords and is an important part of the site you might in some cases also use a h2 instead. Apart from the heading and the paragraph let´s also put our navigation into theheader. Inside the navigation section we put an unordered list with all the navigation links as list items. Your header code should now look like this.
On the website structure image the next area below the header is called “Slider-Images”. As you can see when you look at the preview of our website this area will contain a large jQuery image slider which changes the image every 6 seconds. There are plenty of jQuery Sliders out there but in this tutorial we will use the responsive slideshow plug-in SlideJS which you should download now.
As you can see in the example files of SlideJS the Slider needs a new div called “slides” which contains the images you want to be slided. As we are going to show content boxes on top of the images we will wrap the div “slides” into a new section “container” and add the content for each image into a separate article which we call “slider_content1”, “slider_content2”, “slider_content3″… We are using IDs instead of classes here because we want to address each article with jQuery later on and need to be sure that each one appears only once on the page. The reason why we used articles for the first three sections and then a simple div for the slides is that the articles contain our independent content while the div only contains our three slider images and mainly has a styling purpose. If you are looking for royalty-free images that you can use in your web project please visit Open-Image.net.
Now let´s add the slider content into our markup. “slider_content1” will be the content which is shown when the image “slide1.jpg” is displayed, “slider_content2” for “slide2.jpg” and so on. Inside thesearticles let´s add a heading, some teaser text and a read-more link. Note that we also add a heading with a class “hidden” into the section as we want to create a proper HTML5 outline. If you have problems deciding which heading to use on your website my recommendation is to try to use a heading structure with elements of the appropriate rank for the section’s nesting level. Read this article if you would like to know more about proper use of headings in sections. You´re whole code for the slider should now look like this (I added some blind text into headings and paragraphs).
Now that we have the HTML structure of the image slider let´s move on to the next element on our structure image. As you can see the next thing to do would be the spacer. I called it spacer although it is not actually a spacer, it is just some orange part below the image slider with a short sentence and a search field. For the spacer we use a new section with the ID “spacer”. The reason I used an ID instead of a class for all the sections on the website is that I would like to be able to directly link to a specific part of the website (e.g. http://www.lingulo.com/tutorial-content/html5/#spacer directly scrolls down to the spacer). Inside the spacer we put a short sentence into a new paragraph and another div with the class “search”, which contains our search form.
You are doing great, we already have almost half of the whole HTML5 code we need. Take a look at the structure image again. You can see that from now on we have almost only “articles”, which are wrapped inside containers.
Let´s continue with the next section which contains three articles with a heading and an icon next to it. The icons I used in my tutorial are from Visualpharm and can be found here. Also add a heading h3and a paragraph p with some text to the articles. The br class=”clear” is used to clear the floating of the three articles which we will add into our CSS file in the next part of this tutorial.
Now let´s create our next section again with a h2 heading and four articles in it. Inside the articles we put a hidden heading h3 and a new HTML5 element called figure. The figure element is used in conjunction with the figcaption element to mark up images or diagrams (among others) and should be an independent part which can be moved away from the main flow of the document. Create a figureelement and add an image and a figcaption to it.
If you move your mouse over the images in the website preview you will see that they will become dark and there will be a magnifier icon on top. When clicking on an image Lightbox2 will open the image up in a larger version. We have already included the Lightbox2 script into our head part. To enable image resizing we now need to create an anchor around our image and give it the attribute rel=”lightbox”. Thehref attribute should point to the large image version.
The effect with the magnifier icon on mouse hover is created purely with CSS3 features. The HTML element used to create the half transparent black layer is a span element wrapped inside the anchor. We will style the span in the second part of this tutorial to make it invisible by default and only show it on mouse hover.
Your code for the section “four_columns” should look like this.
Next thing we need is another section with a hidden heading, an article and another section in it. The second section contains a hidden heading and two articles which each contain also a hidden heading. Give the outer section an ID, for example “text_columns” and each of the columns a class, for example “column1” and “column2”. We could of course also not use classes and address the article andsection directly. The reason I like to use classes though is that it makes it easier in case you want to change the HTML code later on without having to change the CSS code.
Inside the first column put a heading h3 and a paragraph p with some text. Into the second column we will put two articles or divs depending on whether the content is relevant and independent or not. Inside each of these two wrappers add a paragraph p and an image. The images need a class “rocket” and “clock” and will be animated later on in the second part of this tutorial.
Inside the first column put a heading h3 and a paragraph p with some text. Into the second column we will put two articles or divs depending on whether the content is relevant and independent or not. Inside each of these two wrappers add a paragraph p and an image. The images need a class “rocket” and “clock” and will be animated later on in the second part of this tutorial.
We have already reached the footer of our website. Into the footer we are going to put not only a hidden heading and a section with three articles for the upper three columns of the footer but also anothersection with the ID “copyright” which we are going to position at the bottom of our footer later in the second part of this tutorial. Into the “copyright” section we add a div with the class “wrapper” which will make sure the content is centered and does not exceed the maximum width (we are going to talk about that in the second part more detailed). The reason we are using a div here instead of an articleis that in this case all we need is a container for styling purposes, there is no actual related and independent content inside. Into the “wrapper” div we put a copyright note as blank text and anotherdiv with the class “social” which contains all the social links.
The section which we just created at the beginning of the footer again gets a hidden heading and contains three articles with the class “column”. To the second and third article we need to assign another class so we can later on target each article separately in CSS. Add the class “midlist” to the second article and the class “rightlist” to the third one. To do so simply add a blank space after “column” and put the other class behind (<article class=”column midlist”>). Into the articles we need to add some content, into the first one let´s just put a heading and a text. Into the one in the middle and the one in the right also put a heading and an unordered list with a link inside each of the list items. Each link should be wrapped around an image and a span element. The span contains our text that we want to display. We are using a span to be able to position the text in any way we want and display it as a block element (more about that later).
That´s it already! Close the body tag and the html tag and we are ready with the basic structure of our webpage. To view the entire HTML code click here.
In the second part of the tutorial we are going to style our website to make it look like in the preview but we are also going to add some more HTML code when it comes to responsive design.
I hope you liked the first part of the tutorial, please feel free to tell me how you liked it in the comment section. To continue with the second (which is also the last part) of this tutorial, click here:
Learn Web Development Using HTML5 Advanced Programing
☞ https://hii.to/4kQHc9_
☞ https://hii.to/4kQHc9_
Learn to Make an Animated Image Gallery using HTML5
☞ https://hii.to/NyNXzCyYx
☞ https://hii.to/NyNXzCyYx
HTML5 Apps Development Fundamentals Tutorial
https://goo.gl/tGxpxE
https://goo.gl/tGxpxE
Building Apps for Office with AngularJS and Html5
http://goo.gl/VYljC4
http://goo.gl/VYljC4
Building Apps for Office with AngularJS and Html5
http://goo.gl/ICn0pI
http://goo.gl/ICn0pI
Learn Responsive Web Development from Scratch ☞ https://school.codequs.com/p/By_x_GQu
The Complete Web Developer Course - Build 14 Websites ☞ https://school.codequs.com/p/HJ1gIdDd
Learn Rails: Build a Network Chatroom ☞ https://school.codequs.com/p/ByysfMId
The Complete Web Developer Course - Build 14 Websites ☞ https://school.codequs.com/p/HJ1gIdDd
Learn Rails: Build a Network Chatroom ☞ https://school.codequs.com/p/ByysfMId
Build Web Apps with React JS and Flux
☞ https://school.codequs.com/p/HkqNSvIO
☞ https://school.codequs.com/p/HkqNSvIO
No comments:
Post a Comment