Advertisement
  1. Web Design
  2. CSS
Webdesign

How to Build a Static Portfolio Page With CSS & JavaScript

by
Difficulty:IntermediateLength:MediumLanguages:

In this tutorial we’ll use all the power of flexbox and learn to build a simple, yet attractive static HTML portfolio page. We’ll also create a responsive column chart without using any external JavaScript library, SVG, or the canvas element. Just with plain CSS!

Here’s the project that we’re going to create (click the Skills link in the top corner):

Note: This tutorial assumes some flexbox knowledge. If you’re just beginning, Anna Monus has a great collection of primers to get you started:

1. Begin With the Page Markup

The page markup is pretty straightforward; a header, a heading, a mailto link and a section:

Inside the section, we put a close button and a wrapper element with two lists. These lists are responsible for building the column chart:

Note: Beyond the elements’ specific classes, our markup contains a number of utility (helper) classes. We’ll use this methodology to keep our CSS as DRY as possible. However, for readability reasons, within the CSS we won’t group common CSS rules.

2. Define Some Basic Styles

Following what we’ve just discussed above, we now specify some reset rules along with a number of helper classes:

The naming conventions for our helper classes are inspired by Bootstrap 4’s class names.

3. Style the Page Layout

The page layout will be as simple as this:

The page layout

Here are the design requirements:

  • The page should be full-screen.
  • The logo is placed to the top left of the page, the menu to the top right, and the mailto link to the bottom right.
  • The heading is horizontally and vertically centered.
  • The section which contains the chart is initially hidden (off-screen).

Here are the corresponding styles to get all that done:

Progress so Far

Here’s what we've built so far!

4. Toggling the Section

Initially, as discussed above, the section is hidden. It will become visible with a nice slide-in effect each time we click on the menu link. We’ll do this by adding the window-opened class to the body element and altering the CSS as needed. In the same way, the section will disappear as soon as we click on the close button.

As a bonus, we’ll give ourselves the ability to set the direction of the slide-in animation. We can pass the data-slideIn custom attribute to the section which will determine the starting position of its animation. Possible attribute values are to-top, to-bottom, and to-right. By default, the section appears from right to left.

Here are the associated styles:

And the JavaScript code needed for toggling its state:

5. Style the Chart

At this point, we’ll have a closer look at the contents of our section. First we have the close button located to the top right side of the section.

Here’s its markup:

And its styles:

Next we have the chart itself. Let’s also revisit its structure:

Here are the key points regarding this markup:

  • We set the .chart-wrapper element as a flex container with two lists as flex items.
  • The second list, which measures the knowledge for a certain skill, is itself a flex container. We give it flex-grow: 1 to grow and take up all the available space.

The initial CSS rules for our chart:

At this point we’ll have a closer look at the items of the second list. 

Things to remember:

  • They all have a width of 12%. We evenly distribute them across the main axis by giving justify-content: space-around to the parent list.
  • They should sit at the bottom of their container, and thus we set align-items: flex-end to the parent list.
  • Their initial height is 0. As soon as the section becomes visible, their height is animated and receives a value equal to the value of their data-height attribute. Just keep in mind that we have to rewrite the desired height values in our CSS because setting height: attr(data-height) doesn’t work :(

Here are the related styles:

As you can see from the code above, we use the transition-delay and transition-delay-step CSS variables along with the calc() CSS function to control the speed of the transition effects. Microsoft Edge doesn’t support those math operations though, so if you need to support it, just pass some static values instead, like this:

To output the amount of knowledge stated for a certain technology, we’ll use the ::before pseudo-element.

Using sudo element to output the amount of knowledge

This value is extracted from the data-height attribute which is assigned to the items of the second list. 

Here are the styles which do this job:

Lastly, we add some styles to the span element which is located inside each of the list items. This element behaves as a label and stores the technology names.

The technology names

The corresponding styles:

6. Go Responsive

We’re almost done! As a last thing, let’s ensure that the page has a solid appearance across all screens. We’ll apply two rules specifically for narrow screens: 

One important note here is that in our styles we’ve used rem for setting the font sizes. This approach is really useful because the font sizes aren’t absolute and their values depend on the value of the root element. So, if we decrease the font size of the root element like in the code above, the rem-related font sizes will be dynamically decreased. Nice job folks!

The final state of our project:

7. Browser Support

The demo works well in all recent browsers and devices. 

As already discussed earlier, Microsoft Edge still doesn’t support math operations with custom properties inside the calc() function. To overcome this issue, you’ll need to use hard-coded values instead.


Conclusion

In this tutorial, we improved our flexbox skills by building an attractive static portfolio page. We even challenged ourselves by learning to create a responsive column chart without using any external JavaScript library, SVG, or the canvas element. Just with plain CSS!

Hopefully you enjoyed this tutorial as much as I enjoyed writing it, and you’ll use this demo as inspiration for developing your own portfolio site. I’d love to see your work–be sure to share it with us!

Further Reading

Advertisement
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.