Advertisement
  1. Web Design
  2. HTML/CSS
  3. CSS

Styling Our Behance Portfolio Website Using LESS

Scroll to top
This post is part of a series called Build Your Own Behance-Powered Portfolio.
How to Use the Behance API to Build a Custom Portfolio Web Page
Bringing Our Behance Portfolio Alive With CSS Animation

During the previous part of this series, we learned about the Behance API, using it to capture a user's portfolio pieces and display them on a web page. In this part we will style the web page, presenting the portfolio pieces in a suitably attractive way. 

Tools We'll be Using

To get started, we will prepare our toolkit:

Normalize

We will use Normalize to make the basic element styles more consistent across different browsers and minimize the chance of unexpected results.

LESS Mixins Libraries

We will also be using LESS for styling our website. Whichever preprocessor you prefer, it's definitely recommendable to use them in your workflow. I'm a big fan of, instead of having to trawl the desired color in the color picker from a separate application, simply using LESS control functions such as lighten() and darken() to give us a range of color variants.

To help us further, we will use LESSHat to help us write less code with its Mixins collection. We will also use Remixins developed by Christopher Ramírez. Remixins is a collection of Mixins to convert px into rem units in. The collection includes the Mixins for specifying font-size, margin, padding, width and height, and CSS position (left, right, bottom, and top).

In addition, we will also need a tool to compile LESS into regular CSS. In this tutorial, we will use an app called Koala, which is available in Windows, OSX, and Ubuntu. You can, of course, use whatever compiler you prefer, but with any luck, you'll be able to follow this tutorial regardless of the platform you are using.

For more about LESS, please refer to these tutorials:

Google Fonts

Default system fonts like Arial just aren't doing it for me today. So in this tutorial I will use Google Fonts instead. I've picked Cantata One for the heading and Open Sans for the default body text. This is a personal preference, you're free to exclude Google Fonts or use alternatives if you wish.

Foundation Icon Fonts

We will also use font icons for a bit of decoration on our website. These days we have a ton of options for font icons. However, during my search I was quite surprise that only few of these fonts include the Behance icon in their collection. In any case, for this tutorial we will use Foundation Icon Fonts 3, as it has includes the Behance icon and is also available through a CDN.

Setting up Our Assets and Tools

In our project root directory, let's create some new folders named less and css (which will be the output folder of the LESS file). Create a new file named style.less and grab Remixins as well as LESShat. Put these three LESS stylesheets in the less folder. At this stage, the list of files and folders in our project directory should look like this:

1
|-- css
2
|-- index.html
3
`-- less
4
    |-- lesshat.less
5
    |-- remixins.less
6
    `-- style.less

Then add Normalize, the Foundation Icon Fonts, and our Google Font stylesheet inside the head tag, along with style.css, which will be the output file of style.less.

1
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/normalize/3.0.1/normalize.min.css">
2
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.min.css">
3
<link href='http://fonts.googleapis.com/css?family=Cantata+One|Open+Sans:300,600' rel='stylesheet' type='text/css'>
4
<link rel="stylesheet" href="css/style.css">
5
6
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
7
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.3.0/handlebars.min.js"></script>

Also, open Koala app (or whichever form of compiling you prefer) and add our project directory to it.

The project directory in Koala

 Adding the Icon Fonts

Before we write any styles, let's add a few icons to our website. First we will add the map location mark beside the user's location element with the fi-marker class. Add this class in beside the profile-location class like so:

1
...
2
<div class="profile-location fi-marker">{{user.city}}, {{user.country}}</div>
3
...

This will add a :before pseudo element to the div, injecting the marker icon in through our Foundation Icons. Next, we will add the Behance logo into the footer section with the fi-social-behance class.

1
...
2
<p><a class="power-logo fi-social-behance" href="http://www.behance.net/" title="Behance" target="_blank">Behance</a></p>
3
...

Setting up Mixins and Variables

Let's open our style.less, and import both lesshat.less and remixins.less using the  (reference) mark.

1
@import (reference) 'lesshat.less';
2
@import (reference) 'remixins.less';

The (reference) mark was introduced in LESS 1.5. It means that LESS will use the file only as reference, it will not compile and output the content into the file. It's a very powerful feature which minimizes duplicate and unnecessary styles.

Inside style.less, we'll add the following variables which store the color palette and font family of our website.

1
@bg-body   : #fafafa;
2
@bg-header : #303746;
3
4
@color-base  : #353537;
5
@color-name  : #e0e0e0;
6
@color-title : #6b919f;
7
8
@font-body  : 'Open Sans', Arial, sans-serif;
9
@font-name  : 'Cantata One', Georgia, Times, serif;

Placing these variables in one place acts as a sort of style guide, but it also helps us to maintain our styles in a more convenient way. For instance, if there's anything in the website we want to change, we can simply change the value within these variables. It's a much safer way to modify styles, instead of performing "Search and Replace".

Starting to Style

Basic Element Styles

Even though we have added Normalize which has standardized our elements styles, we still have a few styles to tweak to follow our particular need. To begin, we will alter the box-sizing, setting all the elements' (including the pseudo-elements') box-sizing to border-box. This will give our dimensions a much more controllable basis to work from. 

We can apply this with the .box-sizing Mixins from LESSHat library, as follows:

1
*, *:before, *:after {
2
    .box-sizing(border-box);
3
}

Next, we will set the html font size to 62.5%, which is one approach to making relative units more manageable.

1
html {
2
    font-size: 62.5%;
3
}

62.5% here is measured against the browser standard of 1em which is 16px; so 62.5% of 16px is equal to 10. By doing this, we will easily be able to figure out the conversion of rem in px by multiplying it by 10. 1.2rem, for instance, will be equal to 12px and so forth. In addition to this, if we take a look at remixins.less source, we will find the base font size in @base-font-size-px variable is set to 10. 

You can refer these articles for further on CSS relative unit:

We use a figure element to contain the portfolio image cover. But our figure element has inherited margin values from Normalize which causes unintended white-space between the portfolio images. So, here we will remove the margin from the figure element.

1
figure {
2
    margin: 0; /*overwrite Normalize.css default style*/
3
}

The Clearfix Hack

Using a clearfix hack is a popular method as a recourse to some layout troubles caused by floating elements failing to clear their child elements. So here we will add the clearfix tip by Nicolas Gallagher which we have turned into LESS.

1
.clearfix {
2
    *zoom: 1;
3
    &:before,
4
    &:after {
5
        content:" ";
6
        display: table;    
7
    }
8
    &:after {
9
        clear: both;    
10
    }
11
}

If you take a look at our HTML structure, we have added clearfix class to some elements.

The Body Styles

For the body, we will set the the font styles that apply through the entire page. These styles include the font size, font color, font weight, font family and the background color. Here, we will use the .font-size() mixin from Remixins library to generate the font size. All Mixins included in the Remixins library generate a px unit fallback, helpful for browsers that do not support the rem unit.

1
body {
2
    .font-size(16px);
3
    background-color: @bg-body;
4
    color: @color-base;
5
    font-family: @font-base;
6
    font-weight: 300;
7
}

Having saved the file, Koala will automatically compile the output. And the above code should look like this in regular CSS.

1
body {
2
  font-size: 16px;
3
  font-size: 1.6rem;
4
  background-color: #fafafa;
5
  color: #353537;
6
  font-family: 'Open Sans', Arial, sans-serif;
7
  font-weight: 300;
8
}

The Header Styles

Next, we will add the styles for the website Header, as follows.

1
.portfolio-header {
2
    .padding(50px, 0);
3
    background-color: @bg-header;
4
    text-align: center;
5
    .profile-avatar img {
6
        .size(80px);
7
        border-radius: 50%;
8
    }
9
    .profile-name {
10
        .font-size(24px);
11
        .margin-bottom(10px);
12
        color: @color-name;
13
        font-family: @font-name;
14
        font-weight: 400;
15
    }
16
    .profile-fields {
17
        .max-width(320px);
18
        .font-size(14px);
19
        color: lighten(@bg-header, 50%);
20
        margin-left: auto;
21
        margin-right: auto;
22
        .field-list {
23
            padding: 0;
24
        }
25
        .field-item {
26
            display: inline-block;
27
            &:after {
28
                content:' ,';
29
            }
30
            &:last-child:after {
31
                content:'';
32
            }
33
        }
34
    }
35
    .profile-location {
36
        .font-size(14px);
37
        color: lighten(@bg-header, 30%);
38
        &:before {
39
            .margin-right(10px);
40
            .font-size(18px);
41
        }
42
    }
43
}

This is quite a chunk of syntax, so let's break it down into pieces and examine what it's doing. Firstly, we've added background color in the Header with the color stored in our @bg-header variable. We use .padding() Mixins from Remixins to add padding at the top and bottom side of the Header, thus delivering more vertical white-space. We've also added text-align:center so our content looks more in order.

1
.portfolio-header {
2
    .padding(50px, 0);
3
    background-color: @bg-header;
4
    text-align: center;
5
...

We've set the user's avatar image size with .size() Mixins and made circlular by setting the border-radius to 50%. You can see these styles are declared in .profile-avatar img.

1
.profile-avatar img {
2
    .size(80px);
3
    border-radius: 50%;
4
}

Below are the rules for the user's name. Here we set the font size with a .font-size() mixin. We've deployed the @color-name variable for the font color, and passed the font family with the @font-family variable. And lastly, we've added font-weight: 400; to make the font look bolder than the rest.

1
.profile-name {
2
    .font-size(24px);
3
    .margin-bottom(10px);
4
    color: @color-name;
5
    font-family: @font-name;
6
    font-weight: 400;
7
}

Next, we will look at the rules for the user creative fields area, which we target with .profile-fields. In Behance, you can add as many skills or field specialties as you wish. That means each user may have short, or really long skill descriptions. I've therefore decided to set the width with a max-width. We set the font color for 50% lighter from the Header background with lighten(@bg-header, 50%).

Furthermore, each of the field items is separated by a comma which we've supplied through an :after pseudo-element. However, logically, the last item should not have a comma, so we've selected the last item with :last-child and set the content property to be empty content:''.

1
.profile-fields {
2
    .max-width(320px);
3
    .font-size(14px);
4
    color: lighten(@bg-header, 50%);
5
    margin-left: auto;
6
    margin-right: auto;
7
    .field-list {
8
        padding: 0;
9
    }
10
    .field-item {
11
        display: inline-block;
12
        &:after {
13
            content:' ,';
14
        }
15
        &:last-child:after {
16
            content:'';
17
        }
18
    }
19
}

Following, are the style rules for styling the user location. Here we set the color slightly lighter than the background color, 30% to be exact. And we've also slightly extended the gap between the text and the marker icon from Foundation Icon Fonts by adding margin-right to the :before pseudo-element.

1
.profile-location {
2
    .font-size(14px);
3
    color: lighten(@bg-header, 30%);
4
    &:before {
5
        .margin-right(10px);
6
        .font-size(18px);
7
    }
8
}

After adding these styles, the Header should now look something like this:

Styling the Portfolio Section

The following snippet contains all the styles for our portfolio.

1
.portfolio-area {
2
    .margin(50px, auto);
3
    .max-width(960px);
4
    width: 100%;
5
    .portfolio-list {
6
        padding-left: 0;
7
    }
8
    .portfolio-item {
9
        .margin-bottom(30px);
10
        .height(320px);
11
        .padding(0, 15px);
12
        float: left;
13
        list-style-type: none;
14
        width: 33,33333333333333%;
15
    }
16
    .portfolio-content {
17
        text-align: center;
18
    }
19
    .portfolio-cover {
20
        width: 100%;
21
    }
22
    .portfolio-image {
23
        border: 8px solid #fff;
24
        max-width: 100%;
25
    }
26
    .portfolio-title {
27
        .font-size(14px);
28
        color: darken(@color-title, 10%);
29
        text-transform: capitalize;
30
        vertical-align: middle;
31
        width: 100%;
32
    }
33
    .portfolio-fields {
34
        .font-size(12px);
35
        color: darken(@bg-body, 30%);
36
        .field-list {
37
            padding: 0;
38
        }
39
        .field-item {
40
            display: inline-block;
41
            &:after {
42
                content:' ,';
43
            }
44
            &:last-child:after {
45
                content:'';
46
            }
47
        }
48
    }
49
}

Many of the styles above are decorative. But here are a few key things worth noting:

First, we set the .portfolio-area width to 100%, but preserve the maximum width at 960px. This will allow the width to adapt gracefully in smaller viewport size. Also, as you can see above, we've set the .portfolio-item width to 33,33333333333333%. This is because we will display three items on each row. The 33,33333333333333% is derived from the division of 100% by 3.

The .portfolio-cover width is set to 100%, it will therefore fill its parent's width. The .portfolio-image is set with max-width:100% so the image will not exceed the parent width regardless of the size. All these width settings will help us make our website fluid.

Now, the portfolio section should looks like this.

Styling the Footer

Next, we will add the styles for the Footer. The Footer is plain and simple; it only consists of "Powered by" text and a Behance icon from Foundation Icon Fonts. Below are all the style rules for the Footer.

1
.portfolio-footer {
2
    .margin(30px, auto);
3
    .max-width(960px);
4
    text-align: center;
5
    width: 100%;
6
    .power-by {
7
        .font-size(12px);
8
        color: darken(@bg-body, 30%);
9
        text-transform: uppercase;
10
    }
11
    .power-logo {
12
        .width(36px);
13
        .height(36px);
14
        color: #1769ff;
15
        display: inline-block;
16
        margin: 0 auto;
17
        overflow: hidden;
18
        position: relative;
19
        text-decoration: none;
20
        text-indent: 100%;
21
        white-space: nowrap;
22
        &:before {
23
            .line-height(38px);
24
            .font-size(36px);
25
            display: inline-block;
26
            height: 100%;
27
            left: 0;
28
            position: absolute;
29
            text-indent: 0;
30
            top: 0;
31
            width: 100%;
32
        }
33
    }
34
}

Similarly to the portfolio section, we set the Footer width to 100% and align it to the center of the browser's window with margin: 0 auto;. We also align all the content to the center to make it look orderly. We then hide the text inside .power-logo using the Kellum Method and display only the Behance logo with its brand color, blue #1769ff.

Note: Behance have a whole developer's section on their Branding Guidelines if you want to take a look.

The Footer should now look fairly complete, like so.

Making the Website Responsive

We have a fluid layout, but now we are going to make our web page responsive. Fortunately, our website is just a single page website with a very simple layout. So it won't require any lengthy code to make it responsive. To begin with, we will add the (crucial) meta viewport in the head tag.

1
<meta name="viewport" content="width=device-width, initial-scale=1.0">

Next we add some Media Queries, as follows.

1
@media only screen and (min-width: 768px) and (max-width: 959px) {
2
    .portfolio-area .portfolio-item {
3
        width: 50%;
4
    }
5
}
6
@media only screen and (max-width: 767px) {
7
    .portfolio-area .portfolio-item {
8
        height: auto;
9
        width: 100%;
10
    }
11
}

These media queries will display two items in a row between 959px and 768px viewport width, and one item when the viewport width is 767px and lower.

Our portfolio website in different viewport sizes

Next Time...

Having styled the aesthetics of our page, all that's left to do is add some flair. In the next and final part of this series, we'll allow visitors to click on each thumbnail and see a larger version, plus we'll add some CSS3 animations to improve the experience.

Advertisement
Did you find this post useful?
Want a weekly email summary?
Subscribe below and we’ll send you a weekly email summary of all new Web Design tutorials. Never miss out on learning about the next big thing.
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.