# Creating an Adaptive, Filterable Portfolio Using jQuery Isotope

Today we'll be taking a PSD Portfolio layout from ThemeForest, replicating it entirely in HTML & CSS whilst making it adaptive. We'll then go further and integrate the Isotope jQuery plugin to make it a fully functional filterable portfolio.

## Step 1: Organizing the Project

We'll start off by creating a simple project structure so everything is kept organized. We'll create three folders:

• css - for our CSS files
• images - all images will be placed in here
• js - for our jQuery plugins and custom scripts

## Step 2: Document

Before we get stuck into our coding we'll create the index.html file which can be placed in the root of your project. We'll throw in a basic HTML5 template, linking to our CSS file in the head. Additionally, we'll need to link to some more files:

• jQuery Library - We'll need to link to the jQuery library ready for later on when we use the Isotope plugin, we'll go ahead and throw that in now. I've gone and used the library hosted by Google (highly recommended).
• HTML5 Shiv - Since we'll be using HTML5 elements we'll need to make sure we link to the HTML5 Shiv to allow the elements to be recognized in older IE versions.
• Google Web Fonts - If you look at the PSD you'll notice that the font PT Sans is used. Since this font won't be locally available for many users we'll link to it using the Google Web Fonts service.

## Step 3: Adding General Styles

We'll now need some general styles in our CSS file. This will involve just a simple reset which you can add to the top of your CSS file.

## Step 4: Starting With the Header

Now we'll begin building the structure of the site! We'll start off with the header and do so by using the HTML5 Header element.

Next we'll add some CSS for our header. We'll apply some basic styles here, but the main aspect to take into account is the positioning. Here we're using a position of fixed and then 0 on the top, left and right. This will ensure our header stays at the top of the window when scrolling - and that it fills the whole height of the browser.

## Step 5: The Logo and "Hire Me" Badge

For simplicity's sake, both these parts will be carried out using images, but we'll also wrap them within anchor tags and give them a class so we can set some styles for positioning.

Both of these use similar styling, both positioned absolutely (the header being the parent) with a 0 top. The logo has left of 0 to keep it on the left and the hire-me badge a right of 20px to push it slightly off from the right.

You should have something that looks like this:

## Step 6: The Sidebar

Once again we'll take advantage of HTML5's markup and create our sidebar using the aside element.

Onto the CSS for the sidebar, you'll notice that we've used position fixed again, technically this doesn't really apply here as the slider is going to fill the height of the page.

## Step 7: Sidebar Background!

You'll notice we've failed to define a background.. We'll apply the sidebar background, but not to the sidebar; we'll apply it to the body and repeat it on the y-axis so it runs from top to bottom. A position of left will also be used to ensure the background is placed on the left side of the page for the sidebar.

Seeing as this is a body style it may make sense to scroll up your CSS file and place it nearer the top. I also went ahead and added a font smoothening property for webkit browsers.

We'll have now completed the base of our sidebar!

Now the sidebar is made we can add the navigation to it. We'll create an unordered list and wrap it with the HTML5 Nav element.

Now some basic styling for the navigation, adding a background, font styles and also the font family from Google Web Fonts - PT Sans.

We'll now need to create a wrapping container which will hold the portfolio entries. Also, we'll have to add some margins and paddings to ensure the entries display in the correct place. This can be done by first moving the entire element away from the header and sidebar.

If we look at the header being 70px high we'll need 70px margin-top. The sidebar is 150px wide so we'll apply 150px margin-left. The final thing is 20px padding on the top and left to push the entries away from the header and sidebar.

## Step 10: Adding a Portfolio Entry

Time to start with the portfolio entries. Go ahead and create a div with a class of portfolio inside our main area, this will hold our portfolio items together. Our portfolio entry is made up of a figure (again an HTML5 element) which is used to denote a container for media of some sort.

We'll then have an image with two spans; one for the ribbon and one for the hover. You could also use pseudo-elements for these, which would lighten the markup, though reduce the browser compatibility of the page.

## Step 11: Styling the Portfolio Item

The styling for the portfolio is basic stuff. We'll float left and add 20px of margin right and bottom. To create the white border we'll simply add some padding and then a background, these will be rounded off using a simple border-radius of 5px (while remembering the prefixes). Finally, a box-shadow will be applied.

As we're applying 20px of margin to the right of the entries we'll need to subtract that off the parent container (the portfolio div).

## Step 12: Adding the Entry Ribbon

We created the ribbon markup when adding the portfolio item (though, again, you may have used a pseudo-element), we'll now need to style it using CSS.

## Step 13: Portfolio Hover State

The last thing to do for the portfolio is to add the hover state. This will be acheived with the span we created previously, all we need now is the styling. We'll use an image and a black background with an alpha opacity of 70%. We've also added some CSS3 transitions to allow a smooth hover effect. The last thing is to add opacity:1; for when hovering over the entry, which will fade in the hover part.

Now our portfolio item is complete, you are free to add you own and change the images!

Now that we have replicated the PSD into a working design, we'll go ahead and make it adaptive. We aren't using a purely flexible grid, which is why what we're practicing isn't technically responsive. We'll use CSS3 Media Queries to change and edit the layout when in different view modes. We'll use rough dimensions, giving us what can more-or-less be perceived as Tablet Portrait Orientation, Tablet Landscape Orientation, Mobile Portrait Orientation and, finally, Mobile Landscape Orientation.

Before we start editing the layout we need to do two things. Firstly we'll need to add the viewport meta tag which will allow our site to be viewed correctly on mobiles and tablets, if you'd like to find out more about this be sure to check out this article by Ian Yates. The last is to add a short bit of CSS to allow our images to be fluid:

## Step 15: Tablet Portrait

We'll start off by targeting tablets with a portrait orientation. Only a small amount of editing is needed to be done to adjust our layout. The main one to take notice of is the entry; it will be made smaller to accommodate more entries on each line.

## Step 16: Tablet Landscape

Usually you wouldn't target the landscape orientation of a tablet unless you really have to, but because of the design of this page it will certainly help us out. We won't use min and max widths to determine the viewport size - we'll target it based on orientation. This time we're using even less code by simply changing the width of the portfolio entry.

## Step 17: Mobile Portrait

We'll move onto mobiles now, starting with portrait orientation. This time we'll have to do a bit more editing. We're going to adjust the layout now, because of the screen getting smaller we're no longer able to accommodate the sidebar on the left with entries on the right. We'll move the sidebar up before the entries and have it fill the entire width of the screen.

Also, due to the header being a large size with the sidebar/navigation beneath it you may not be able to see as many of the entries. We'll remove the position: fixed and change it to absolute so the header will now scroll instead of staying at the top of the page.

## Step 18: Fixing Some Positioning Problems

Okay, now we've run into some problems. The sidebar has adjusted nicely to the screen layout, but portfolio entries are positioning incorrectly. We'll need to go back to our markup and add two extra divs, one with an id of wrapper which will wrap everything other than the header and another with a class of page which will wrap our main content area.

After adding in the necessary markup, we'll have to add some styles. Scroll back on up to the top of your CSS file and add the following:

## Step 19: Mobile Landscape

Okay, finally the landscape orientation for mobile. If you place this after the mobile portrait CSS we just created it'll inherit those styles, .e.g the full width sidebar etc. All we need to do now is change the entry width.

## Step 20: Introducing Isotope

Now we've covered creating the design we can start to give it some functionality! We'll be using the brilliant isotope plugin by David DeSandro. Isotope is used to create layouts, filtering and sorting. It is commonly used on portfolios to filter pieces of work into different categories - for example Web Design, Photography and Illustration. On that note, let's get it installed!

Before we can add it to our design we'll need to download it. Head on over to http://isotope.metafizzy.co/jquery.isotope.min.js. You'll now see the Isotope javascript file, just go to File > Save and save it in the js folder we created at the beginning. We'll need to then link to the script within your HTML file.

## Step 21: The Filtering Process

To allow our portfolio items to be filtered we'll need to change our markup again. We'll start off with the navigation which will filter for us. Isotope uses HTML5 Custom Data Attributes, specifically data-filter="". We set a value depending on the category; Web Design uses .web (note that we have to add a period before the category value). The anchor tag for All categorys doesn't use .all though, it uses an asterisk.

## Step 22: Filtering Portfolio Items

The final part of the filter process is to edit the portfolio items. After adding data-filter values you'll need to add the corresponding values to each entry. If the work entry is in the video category you'll need to add a class of video. Do note that if your data-filter values are lowercase, you must use lowercase for the entry classes.

## Step 23: Hooking the Plugin

It's time to activate Isotope which we'll do in two parts. First we need to hook the part which will sort our portfolio entries. Start off by creating a new file called "custom.js" and place it in your js folder.

## Step 24: Click Function

The second part will hook the navigation to allow the filtering to happen.

## Step 25: Adding an Active State

Shown in the PSD is an active state for the current selected navigation anchor. We'll need to add some more markup, some more CSS and finally some more jQuery. Start off by heading on back to your HTML file and adding class="selected" to the first anchor tag.

The final part is some jQuery, this will add classes when clicked to show the active button/category.

## Step 26: Forgetting Something Are We?

If you go ahead and click the nav buttons you'll see that the filter is working! But wait, it's not a smooth transition! Well that's because we still have to add some CSS transitions.

## Conclusion

And there we go, another useful tutorial complete! You're free to use this method in any designs you have. Go and have some fun with it.

I hope you enjoyed this tutorial, thanks for reading!