Things to Consider
- Convert pixels to percentages using the formula target ÷ context = result
- Carry the decimal of your result over two places to the right to get your percentage
- Do not round up your percentages, no matter how ugly or long the decimal is!
The grid that the Smells Like Bakin website was built on used the tool Gridulator to create a 1000px wide, 12 column grid. Each column is currently 65px with a gutter width of 20px.
Using the same overall width of 1000px, rewrite the grid to have each column instead be 54px wide with a gutter width of 32px.
Then, using the formula target ÷ context = result, convert the new column widths to percentages.
[Website Waters Island 2: Stage 2: Creating a Fluid Foundation with Allison Grayce]
Hey guys and welcome back to Website Waters Island 2.
Let's review what we learned in the previous stage.
We learned how to use the formula target/context = result
to convert font sizes from pixels to EMs.
We also learned the basic differences between fixed, fluid,
adaptive, and responsive web design.
Finally, we learned that the key to a responsive website is building it on a fluid foundation.
That's just what we'll do.
In this stage, we'll convert the fixed grid you worked on in the previous Island
into a fluid grid. Let's get started.
At this point, all of your font sizes in the Smells like Bakin' website
should be converted to EMs if they aren't already.
You might not see a lot of change visually when you view the website in the browser,
but know that it's on its way to becoming a much more scalable and fluid website.
Now go ahead and open up the grid style sheet in your text editor
so we can convert the grid from a fixed to a fluid layout.
The Smells Like Bakin' website was designed at a total width of 1000 pixels.
These 1000 pixels were divided up evenly into a 12-column grid.
Each column is 65 pixels wide with a gutter of 20 pixels between them.
Designing around a grid, while it can be tricky at first to get used to,
is great, because it results in a solid visual and structural balance.
It improve legibility and hierarchy and provides us with the good kinds of constraints.
If we look at the CSS, these 12 classes are the widths of our columns in the grid.
Right now they're in pixels, and we need to change them to percentages.
Below our columns towards the bottom of the style sheet is our website's container div.
Currently, it's set to a width of 1000 pixels.
Now, this is a fixed width, which is fine,
but the problem is that this won't scale with the view port size.
So, we want to change this value to percentages so it scales.
Let's change this width to 90%.
There is no science or formula to this number.
It just makes sure that we have a little bit of buffer or padding between
the browser window and the content of our website.
We're also going to give it a max width of 1000 pixels,
so that our website doesn't continue scaling up past this size.
Now we're going to focus our attention back to our columns
and change the value of the largest column, grid_12, to 100%,
since it should take up 100% of the width of the container.
Now it's time to revisit our favorite formula Target /Context = Result.
Focus on grid_11.
Using the column width 915 pixels as our target,
divide by the width of the entire website--1000 pixels,
which is our context--and we get 0.915.
Now, to convert this number to a percentage,
we need to move the decimal over two places to the right,
so our percentage width is 91.5%.
Consider taking note of the pixel width of the column to the right
by commenting it out with a forward slash and an asterisk,
and then closing it out with an asterisk and a forward slash, like this.
This can be helpful for those of us who are more comfortable with pixel values.
Let's do the same thing for grid_10.
830 pixel divided by 1000 pixels equals 0.83.
Carry the decimal over, and we get 83%.
Continue to work your way down the grid until they're all into percentages.
You have to sign up for Treehouse in order to create workspaces.Sign up
You have to sign up for Treehouse in order to download course videos.Sign up
Allison is a freelance web designer and UX consultant with experience working at small interactive agencies and large advertising firms.