There are countless variations when it comes to different sections that can be incorporated into the design of a single page website. In this tutorial, we will cover how to create a generic section that can be extended to multiple sections. This section provides the ability to display any information your website needs.
Single page sections are commonly used to display the following data to the user:
These are just some of the many uses for sections in a single page website. A good rule of thumb is that if it can be a page on another website it can most likely be adapted into sections on a single page website. Also, depending on the amount of information a single section has, it could potentially be split into multiple sections.
This article is an excerpt taken from the book,' Responsive Web Design by Example', written by Frahaan Hussain.
Let's go through some examples of the sections mentioned above.
As can be seen, by the contact form from Richman, the elements used are very similar to that of a contact page. A form is used with inputs for the various pieces of information required from the user along with a button for submission:
Not all contact forms will have the same fields. Put what you need, it may be more or less, there is no right or wrong answer. Also at the bottom of the section is the company's logo along with some written contact information, which is also very common. Some websites also display a map usually using the Google Maps API; these mainly have a physical presence such as a store.
Website link—http://richman-kcm.com/
This is an excellent example of an about us page that uses the following elements to convey the information:
Website link—http://designedbyfew.com/
This website shows its work off very elegantly and cleanly using images and little text:
It also provides a carousel-like slider to display the work, which is extremely useful for displaying the content bigger without displaying all of it at once and it allows a lot of content for a small section to be used.
Website link: http://peeltheorange.com/#recent-work
This website uses a background image similar to the introduction section created in the previous chapter and an additional image on top to display the opening times.
This can also be achieved using a mixture of text and CSS styling for various facets such as the border.
Website link—http://www.mumbaigate.co.uk/
We will now create a generic section that can easily be modified and reused to our single page portfolio website. But we still need some sort of layout/design in mind before we implement the section, let's go with an Our Team style section.
The Our Team section will be a bit simpler, but it can easily be modified to accommodate the animations and styles displayed on the previously mentioned websites. It will be similar to the following example:
Website link—http://demo.themeum.com/html/oxygen/
The preceding example consists of the following elements:
We will also create our section using a similar layout. We are now finally going to use the column system to its full potential to provide a responsive experience using breakpoints.
First let's implement a simple container, with the title and section introduction text, without any extra elements such as an image. We will then use this to link to our navigation bar. Add the following code to the jumbotron div:
Let's go over what the preceding code is doing:
All of this produces the following result:
We will now link the navigation bar to the Team section. This will allow the user to navigate to the Team section without having to scroll up or down. At the moment, there is no need to scroll up, but when more content is added this can become a problem as a single page website can become quite long. Fortunately, we have already done the heavy lifting with the navigation bar through HTML and JavaScript, phew!
First, let's change the name of the second button in the navigation bar to Team. Update the navigation bar like so:
The navigation bar will now look as follows:
Fantastic, our navigation bar is looking more like what you would see on a real website. Now let's change href to the same ID as the Team section, which was #TeamSection like so:
Now when we click on any of the navigation buttons we get no JavaScript errors like we would have in the previous chapter. Also, it automatically scrolls to each section without any extra JavaScript code.
Now let's use images to showcase the team members. I will use the image from the following link for our employees, but in a real website you would obviously use different images:
http://res.cloudinary.com/dmliyxggm/image/upload/v1511699813/John_vepwoz.png
I have modified the image so all the background is removed and the image is trimmed, so it looks as follows:
Up until now, all images that we have used have been stored on other websites such as CDN's, this is great, but the need may arise when the use of a custom image like the previous one is needed. We can either store it on a CDN, which is a very good approach, and I would recommend Cloudinary (http://cloudinary.com/), or we can store it locally, which we will do now.
Create a folder called Images and place the image using the following folder structure:
This may seem like overkill, considering we only have one image, but as your website gets more complex you will store more images and having an intelligent folder structure/hierarchy will save an immense amount of time.
Add the following code to the first row like so:
The code we have added doesn't actually provide any visual changes as it is nothing but empty div classes. But these div classes will serve as structures for each team member and their respective content such as name and social links.
We created a new row to group our new div classes. Inside each div we will represent each team member. The classes have been set up to be displayed like so:
The sizes/breakpoints can easily be changed using the information regarding the grid from this article What Is Bootstrap, Why Do We Use It?
Now let's add the team's images, update the previous code like so:
The preceding code produces the following result:
As you can see, this is not the desired effect we were looking for. As there are no size restrictions on the image, it is displayed at its original size. Which, on some screens, will produce a result similar to the monstrosity you saw before; worry not, this can easily be fixed.
Add the classes img-fluid and img-thumbnail to each one of the images like so:
The classes we added are designed to provide the following styling:
This produces the following result:
As it can be seen, this is significantly better than our previous result. Depending on the browser/screen size, the positioning will slightly change based on the column breakpoints we specified. As usual, I recommend that you resize the browser to see the different layouts.
These images are almost complete; they look fine on most screen sizes, but they aren't actually centered within their respective div. This is evident in larger screen sizes, as can be seen here:
It isn't very noticeable, but the problem is there, it can be seen to the right of the last image. You probably could get away without fixing this, but when creating anything, from a website to a game, or even a table, the smallest details are what separate the good websites from the amazing websites. This is a simple idea called the aggregation of marginal gains. Fortunately for us, like many times before, Bootstrap offers functionality to resolve our little problem. Simply add the text-center class, to the row within the div of the images like so:
This now produces the following result:
There is one more slight problem that is only noticeable on smaller screens when the images/member containers are stacked on top of each other. The following result is produced:
The problem might not jump out at first glance, but look closely at the gaps between the images that are stacked, or I should say, to the lack of a gap. This isn't the end of the world, but again the small details make an immense difference to the look of a website. This can be easily fixed by adding padding to each team member div. First, add a class of teamMemberContainer to each team member div like so:
Add the following CSS code to the index.css file to provide a more visible gap through the use of padding:
This simple solution now produces the following result:
If you want the gap to be bigger, simply increase the value and lower it to reduce the gap.
The previous section covered quite a lot if you're not 100% on what we did just go back and take a second look. This section will thankfully be very simple as it will incorporate techniques and features we have already covered, to add the following information to each team member:
Update each team member container with the following code:
Let's go over the new code line by line:
The code that we just added will produce the following result:
As usual, resize your browser to simulate different screen sizes. I use Chrome as my main browser, but Safari has an awesome feature baked right in that allows you to see how your website will run on different browsers/devices, this link will help you use this feature—https://www.tekrevue.com/tip/safari-responsive-design-mode/ Most browsers have a plethora of plugins to aid in this process, but not only does Safari have it built in, it works really well.
It all looks fantastic, but again I will nitpick at the gaps. The image is right on top of the team member name text; a small gap would really help improve the visual fidelity. Add a class of teamMemberImage to each image tag as it is demonstrated here:
Now add the following code to the index.css file, which will apply a margin of 10px below the image, hence moving all the content down:
This very simple code will produce the following similar yet subtly different and more visually appealing result:
We have almost completed the Team section, only the social links remain for each team member. I will be using simple images for the social buttons from the following link:
https://simplesharebuttons.com/html-share-buttons/
I will also only be adding three social icons, but feel free to add as many or as few as you need. Add the following code to the button of each team member container:
Let's go over each new line of code:
We have added a class that needs to be implemented, but let's first run our website to see the result without any styling:
It looks OK, but the social icons are a bit big, especially if we were to have more icons. Add the following CSS styling to the index.css file:
This piece of code simply restricts the social icons size to 50px. Only setting the width causes the height to be automatically calculated, this ensures that any changes to the image that involves a ratio change won't mess up the look of the icons. This now produces the following result:
Feel free to change the width to suit your desires. With the social buttons implemented, we are done.
If you've enjoyed this tutorial, check out Responsive Web Design by Example, to create a cool blog page, beautiful portfolio site, or professional business site to make them all totally responsive.
5 things to consider when developing an eCommerce website
What UX designers can teach Machine Learning Engineers? To start with: Model Interpretability