Advertisement

How to Code a Photoshop Layout With CSSHat, LESSHat and PNGHat

by
Final product image
What You'll Be Creating

In the previous tutorial we covered how to prepare a design in Photoshop, ready for conversion to pure CSS3 and Base64 code. In this tutorial we'll be handling the actual code generation, with the help of Photoshop plugins CSSHat and PNGHat made by Source, as well as FontAwesome and the CSS preprocessor LESS.

Let's dive straight in!

Create Your File and Folder Structure 

To begin with you'll need to create a new folder on your computer to house your static website. In this case I'm naming my folder codedup

Inside that folder create a new file named index.html and add to it the following code:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
	<title>Photoshop to Pure Code with CSSHat and PNGHat</title>
	<link href='http://fonts.googleapis.com/css?family=Roboto:100,300,400,700,900' rel='stylesheet' type='text/css'>
	<link rel="stylesheet" href="css/style.css">
</head>
<body>
</body>
</html>

Here, we're setting up the basic HTML shell for the site and linking in Roboto, the Google Font we used in our PSD, as well as what will be our CSS stylesheet.

Next, create two subfolders within your codedup folder, one named css and the other named LESS. Inside the LESS folder create a file named style.less. All the styles for your site will be written into this file, and subsequently compiled into css > style.css.

Note: Structure of your LESS file

As we go along your style.less file should have its code organized in this order:

  1. Imports
  2. Variables
  3. Mixins
  4. Styles

I recommend adding a comment at the top of each section in your style.less file to help you keep track of where different types of code should be placed.

If you prefer, you can create separate files (partials) to house each of these types of code, importing each of them into your main LESS file. However to keep things simple here we'll be using just the one file.

Setup Auto Compiling With Prepros

Prepros is an application which handles all kinds of front end tasks for web designers and developers. It will compile our LESS, auto-refresh the browser whenever changes are made to our files, even synchronise multiple devices if we want. Download and install Prepros, which you can get free from: http://alphapixels.com/prepros/

Run the application, then drag the codedup folder onto the main interface to add it as a new project.

Prepros will automatically detect the style.less file in your project folder and by default will have "Auto Compile" activated. Any time you save a change to style.less Prepros will detect it then compile into css > style.css.

You can also click style.less in the interface to see extra available settings, such as the option of compressing the CSS during compilation.

Incorporate LESSHat and Normalize.less

Now go ahead and grab the files for LESSHat, a mixin library that ties in beautifully with CSSHat, as well as Normalize.less, a version of "Normalize.css" written in LESS friendly syntax.

After downloading the two files and placing them in your project, go back to Prepros and you'll see it has automatically detected both of them. We'll be importing both of these into our main style.less and we don't want them compiling into individual CSS files, so click on each and uncheck "Auto Compile".

Now open up your style.less file in your preferred code editor and add these two lines to the top:

@import "lesshat.less";
@import "normalize.less";

Save your file and Prepros will automatically compile it for you, after which you should see the following popup in the bottom right corner of your screen:

You should now also see the file style.css inside your project's css folder.

Incorporate FontAwesome

We're now going to incorporate FontAwesome into the project by adding the font files themselves as well as "FontAwesome.less", a prebuilt LESS library which makes it incredibly easy to place FontAwesome icons in your designs. All we have to do is import the file and then the FontAwesome classes become instantly accessible. 

You'll see how this works in practice later in the tutorial when we add our "big down arrow" element.

Start by creating a subfolder named font-awesome inside your LESS folder. There are quite a few files in FontAwesome's library so we'll keep them in here to keep oursleves organized

Download FontAwesome as a zip from: https://github.com/FortAwesome/Font-Awesome

Extract the folder and copy all the files from within its less folder, then paste them into the font-awesome folder you just created in your project. Then copy the entire fonts folder from your unzipped FontAwesome download, and paste it as a subfolder into your project.

Your full project file and folder structure should now look like this:

Prepros will again detect new LESS files, so uncheck "Auto Compile" on any files that now appear in the interface.

Add the following line to your style.less file, below the lines you added previously:

@import "font-awesome/font-awesome.less";

Your project now has all the LESS imports and font files you need in place, and automatic compilation activated, so we're ready to start translating your PSD into code.

Incorporate Background Image as Base64

In the previous tutorial we chose the pattern named "Satin Weave" to tile across our background due to its small size and low number of colors. We're now going to use the PNGHat plugin to convert it into a string of Base64 code.

Open up the PSD in Photoshop. We know the dimensions of the pattern are 24px wide by 12px high, so go ahead and use your marquee to create a selection of that size anywhere on your design.

Now, ensuring the background layer that has the pattern applied to it is selected, open up your PNGHat window. All you have to do is click the "Base 64" option in the top row of the window, then click "Export Selected Layers". 

You will see a dialogue appear asking for confirmation you want to "Crop image by selection?". Click Yes and you will see your Base64 string output in the bottom space of the PNGHat window. Click the Copy button.

Head back over to your style.less file and paste the code you just copied from PNGHat into your "Variables" section. Delete everything from the pasted in code except for url(data.......); and then add @satinweave:  at the start of the line. You should end up with:

@satinweave: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAMAgMAAAAFXpXmAAAABGdBTUEAALGPC/xhBQAAAAlQTFRF8vLy7+/v8fHxxV2ZvQAAADRJREFUCNdVysENADAIQlGWkRj3rodOWeDW0w8+0axlg5wlFW/FGyEdTUpeESKOqXBN8+cB4yUS37/ediwAAAAASUVORK5CYII=);

We're now ready to place our new, easy to use @satinweave variable into a style so it will appear in our design. While we're at it we'll also add a couple of basic rules for site wide box-sizing and link settings.

Add the following code to the "Styles" section of your styles.less file:

* {
    .box-sizing(border-box);
}
body {
	background-image: @satinweave;
	overflow-x: hidden;
}
a, a:link, a:visited, a:hover, a:active {
	text-decoration: none;
}

Save your file so that Prepros will compile your changes into your style.css file.

Go to Prepros, click the More Options button and choose Copy live preview URL, (which will most likely be http://localhost:8000), then paste it into your browser. 

This will give you a preview of your static site which automatically reloads each time Prepros compiles your code.

You should now see your pure Base64 pattern tiling across the background of the page.

Adding CSS Elements

Generating CSS3 With CSSHat

It couldn't be simpler to have CSSHat output the CSS3 for each design element. Just select the layer in question with the CSSHat window open and it will automatically generate the code you need.

There are a few options you can choose from in the settings of the CSSHat window. In our case we want our code to be output as LESS, and we want all the little buttons at the bottom of the CSSHat window (comments, dimensions, prefixes, rule) to be deactivated. Your CSSHat window should look like this:


Note that you can have CSSHat generate height and width code for you in px values by clicking the fourth button (which looks like a little square with smaller squares on its corners). However I prefer to write my own, so I can more easily use rem / em / % values where I need them.

When the code for your selected layer has been generated just click the Copy button at the bottom of the window, ready for pasting into your style.less file.

The Element Addition Process

We'll now proceed to add the rest of your design elements via CSS.

Because CSSHat makes thing so easy we can use a pretty much stock standard process which is just repeated until your design is fully coded up.

For each element we'll begin by add the corresponding HTML to the index.html file. 

After that, each new element will involve adding one or more LESS mixins, which we'll use to hold the CSS3 generated by CSSHat. It's helpful to keep your CSSHat generated code separate from the rest of your style code so you can easily update it if you change your design. You should add new mixins to the "Mixins" section of your style.less file, as described above.

Finally, you'll add the actual CSS styles that will be output to your stylesheet. These styles will incorporate your mixins as well as some extra code I'll provide to control layout, dimensions, and aspects Photoshop can't handle such as numerical font-weight and 'one side at a time' borders. Your styles should be added to the "Styles" section of your style.less file.

We'll be creating each design element in the same order as we did in the previous part of this tutorial to make it easy to refer back should you need to.

Add the Top Trim

Add HTML:

Add the following in between your opening and closing body tags.

<br><div class="toptrim"></div>

CSSHat:

Select your PSD's "top trim" layer, and copy the CSSHat generated code:

opacity: .5;
background-color: #ddd;
.box-shadow(~"0 2px 1px #fff, inset 0 -2px 4px #c8c8c8");

New Mixin:

In your style.less file create a new mixin named TopTrim and paste in your CSSHat code like so:

.TopTrim(){
opacity: .5;
background-color: #ddd;
.box-shadow(~"0 2px 1px #fff, inset 0 -2px 4px #c8c8c8");
}

New Style:

We'll now incorporate your new mixin in the "Styles" section of your style.less file. Add the following new style code:

//Top trim
.toptrim {
height: 8px;
margin-bottom: 62px;
.TopTrim();
}

In the above code we're pulling out our CSSHat generated styles via the TopTrim mixin, as well as setting the layout dimensions we need.

Result:

You should now see your "top trim" running across the top of your site.

Create the Menu Wrapper

Add HTML:

Add the following below the last HTML you added:

<nav class="menuwrap">
</nav>

CSSHat to New Mixin:

Select your PSD's "menuwrap" layer, copy the CSSHat generated code, and paste it into a new mixin named MenuWrapBG:

.MenuWrapBG(){
.border-radius(12px);
background-color: #f9f9f9;
.box-shadow(~"0 1px 2px #fff, inset 0 1px 10px rgba(0,0,0,.15)");
.background-image(~"linear-gradient(bottom, #fff 0%, #f3f3f3 100%)");
}

New Style:

Add the following new style code:

//Menu
.menuwrap {
min-height: 61px;
max-width: 1200px;
width:100%;
margin: 0 auto;
padding: 5px;
.MenuWrapBG;
}

Result:

You should now see:

The Menu Background

Add HTML:

Update your existing menu code to the following:

<nav class="menuwrap">
    <ul class="mainmenu">
    </ul>
</nav>

CSSHat to New Mixin:

Select your PSD's menubg layer and copy the CSSHat generated code into a new mixin named MainMenuBG:

.MainMenuBG(){
border: 1px solid #e4e4e4;
.border-radius(11px);
background-color: #fff;
.box-shadow(~"0 3px 4px rgba(193,193,193,.75)");
.background-image(~"linear-gradient(bottom, #e5e5e5 0%, #fff 100%)");
}

New Style:

Add the following new style code:

ul.mainmenu {
    padding: 0 15px;
	margin: 0;
	list-style-type: none;
	min-height:50px;
	.MainMenuBG();
}

Result:

You should now see:

Adding the Menu Items

Add HTML:

Update your existing menu code to the following:

<nav class="menuwrap">
    <ul class="mainmenu">
		<li><a href="#">Page</a></li>
		<li class="current"><a href="#">Current</a></li>
		<li><a href="#">Page</a></li>
		<li><a href="#">Page</a></li>
	</ul>
</nav>

CSSHat to New Menu Item Background Mixin:

In your PSD, select one of your menu item rectangles and copy the CSSHat generated code into a new mixin named MenuItemBG:

.MenuItemBG(){
.background-image(~"linear-gradient(bottom, #eee 0%, #e4e4e4 25.49%, #fbfbfb 100%)");
}

CSSHat to New Menu Item Text Mixin:

In your PSD, select the text of one of your menu items and copy the CSSHat generated code into a new mixin named MenuItemText:

.MenuItemText(){
color: #5b5b5b;
font-family: "Roboto";
font-size: 18px;
text-shadow: 0 1px 0 #fff;
}

Update Your Menu Style:

Update the existing ul.mainmenu style as follows. 

ul.mainmenu {
    padding: 0 15px;
	margin: 0;
	list-style-type: none;
	min-height:50px;
	.MainMenuBG();
	li {
		display: block;
		float: left;
		padding: 0;
		border-top: 1px solid rgba(0,0,0,0);
		border-bottom: 1px solid #dddddd;
		border-right: 1px solid #dddddd;
		border-left: 1px solid rgba(0,0,0,0);
		&:first-of-type{
			border-left: 1px solid #dddddd;
		}
		.MenuItemBG();
		a, a:link, a:visited {
			display:block;
			height: 47px;
			line-height: 47px;
			padding: 0 30px;
			//added font weight
			font-weight: 400;
			.MenuItemText();
		}
	}
}

We're using LESS rule nesting so all li children of ul.mainmenu will be affected. 

You'll also recall in the previous tutorial we had to manually use the line tool to facilitate a color selection for our menu item borders, given Photoshop's inability to set each border side individually. In the above you'll see we incorporate these border styles using the color code #dddddd we selected during that stage. 

We also added some transparent borders on the top and left sides of the menu items. The reason for this is our current item / hover effect will use borders on all four sides, so we need to ensure there is a matching width on menu items in their default and hover states.

And finally we've manually added the correct font-weight of 400 to the menu item text because Photoshop is only able to work with values like "normal" or "bold".

Result:

You should now see:

Create "Current" and Hover States

In this case we don't need any extra HTML as we already added a menu item with the class "current" applied to it in the last step.

CSSHat to New Current Menu Item Background Mixin:

In your PSD, select the rectangle of your "current" menu item and copy the CSSHat generated code into a new mixin named CurrentMenuItemBG:

.CurrentMenuItemBG(){
border: 1px solid #e62d4e;
background-color: #ef3d5d;
.box-shadow(~"0 1px 0 #cc2241, inset 0 2px 5px rgba(250,171,185,.6)");
.background-image(~"linear-gradient(bottom, #ef3d5d 0%, #dc2344 25.49%, #fc6b85 100%)");
}

CSSHat to New Current Menu Item Text Mixin:

Now select the text of your "current" menu item and copy the CSSHat generated code into a new mixin named CurrentMenuItemText:

.CurrentMenuItemText(){
color: #fff;
font-family: "Roboto";
font-size: 18px;
text-shadow: 0 -1px 0 #b50020;
}

Update Menu Style:

Update the existing ul.mainmenu style as follows. 

ul.mainmenu {
    padding: 0 15px;
	margin: 0;
	list-style-type: none;
	min-height:50px;
	.MainMenuBG();
	li {
		display: block;
		float: left;
		padding: 0;
		border-top: 1px solid rgba(0,0,0,0);
		border-bottom: 1px solid rgba(0,0,0,0.05);
		border-right: 1px solid rgba(0,0,0,0.05);
		border-left: 1px solid rgba(0,0,0,0);
		&:first-of-type{
			border-left: 1px solid rgba(0,0,0,0.05);
		}
		.MenuItemBG();
		a, a:link, a:visited {
			display:block;
			height: 47px;
			line-height: 47px;
			padding: 0 30px;
			//added font weight
			font-weight: 400;
			.MenuItemText();
		}
		&:hover {
			.CurrentMenuItemBG();
			a, a:link, a:visited {
				.CurrentMenuItemText()
			}
		}
	}
	li.current {
		.CurrentMenuItemBG();
		a, a:link, a:visited {
			.CurrentMenuItemText()
		}
	}
}

And to allow the menu items to be pushed onto multiple lines if there are two many for the available width, add the following clearfix code below your existing menu class.

ul.mainmenu:before,
ul.mainmenu:after {
    content: " ";
    display: table;
}

ul.mainmenu:after {
    clear: both;
}

Result:

You should now see the "current" style applied both to the actual current menu item and the hover effect:

Add the Main Text

Add HTML:

Add the following code below your menu HTML:

<div class="maintext">
    <p class="thintext">Did you know you can</p>
	<p class="thicktext">Have Your Photoshop</p>
	<p class="thintext">AND YOUR</p>
	<p class="thicktext">Pure Code Too?</p>
</div>

CSSHat to New Mixin, Thin Text:

In your PSD, select either the first or third main text line (thin grey text) and copy the CSSHat generated code into a new mixin named ThinText:

.ThinText(){
color: #6b6b6b;
font-family: "Roboto";
font-size: 48px;
}

CSSHat to New Mixin, Thick Text:

In your PSD, select either the second or fourth main text line (thick text) and copy the CSSHat generated code into a new mixin named ThickText:

.ThickText(){
color: #ef3d5d;
font-family: "Roboto";
font-size: 80px;
font-weight: bold;
}

New Styles:

Add the following new style code:

//Main text lines
.maintext {
    padding: 70px 0;
	text-align: center;
}
.thintext {
	margin: 0.425em 0;
	//added font weight
	font-weight: 100;
	.ThinText();
}

.thicktext {
	margin: 0.425em 0;
	.ThickText();
}

Result:

You should now see this below your menu:

Create the Info Panel Background

Add HTML:

Add the following code:

<div class="panel">
</div>

CSSHat to New Mixin:

In your PSD, select your info panel background rectangle and copy the CSSHat generated code into a new mixin named PanelBG:

//Panel mixins
.PanelBG(){
border: 1px solid #d7d7d7;
.border-radius(15px);
background-color: #fff;
.box-shadow(~"0 3px 4px rgba(193,193,193,.27)");
}

New Style:

Add the following new style code:

.panel {
    max-width: 1200px;
	width:100%;
	margin: 0 auto;
	padding-bottom: 50px;
	text-align: center;
	.PanelBG();
}

Result:

You should now see your info panel background, currently still empty:

Panel Header Background and Text

Add HTML:

Update your info panel HTML to the following:

<div class="panel">
    <div class="panelhead">IN THIS TUTORIAL:</div>
</div>

CSSHat to New Mixin, Panel Header Background:

In your PSD, select your panel header background layer and copy the CSSHat generated code into a new mixin named PanelHeadBG:

.PanelHeadBG(){
.border-radius(10px);
background-color: #ef3d5d;
.box-shadow(~"0 3px 0 #cc2241, inset 0 0 5px rgba(222,42,74,.6)");
.background-image(~"linear-gradient(bottom, #ee2c4f 0%, #dc2344 10.5%, #fc6b85 100%)");
}

Add Panel Header Second Shadow:

We're now going to add a second shadow to the PanelHeadBG mixin we've already created. You'll recall from Part 1 of this tutorial that we had to create additional shadows on second layers due to Photoshop not being able to handle multiple drop shadows on one layer.

In your PSD, select your panel header second shadow layer and copy only the code between the parenthesis on the box-shadow line, which should be:

0 5px 3px rgba(0,0,0,.27)

In the PanelHeadBG mixin you just created, add a comma before the closing parenthesis of the existing box-shadow line, then paste in the code you just took from CSSHat to give you:

.box-shadow(~"0 3px 0 #cc2241, inset 0 0 5px rgba(222,42,74,.6), 0 5px 3px rgba(0,0,0,.27)");

CSSHat to New Mixin, Panel Header Text:

In your PSD, select your panel header text, and copy the CSSHat generated code into a new mixin named PanelHeadText:

.PanelHeadText(){
color: #fff;
font-family: "Roboto";
font-size: 24px;
text-shadow: 0 -1px 0 #b50020;
}

New Style:

Add the following new style code:

.panelhead {
    margin: 60px -15px;
	padding: 20px;
	.PanelHeadBG();
	//added font weight
	font-weight: 400;
	.PanelHeadText();
}

Note that we added a font-weight of 400 manually given Photoshop can't process numerical font weight values.

Result:

You should now see:

Create the Panel Text

Add HTML:

Update your existing panel HTML code again, this time to the following:

<div class="panel">
    <div class="panelhead">IN THIS TUTORIAL:</div>
	<p>Learn how to design in Photoshop and output<br />standards ready pure CSS3 + Base64 code.</p>
	<p>That means no images and minimal HTTP<br />requests for ultra efficient loading.</p>
	<p class="usingthese">CSSHat <span class="highlight">+</span> PNGHat <span class="highlight">+</span> LESS <span class="highlight">+</span> FontAwesome</p>
</div>

CSSHat to New Mixin, Default Panel Text:

In your PSD, select the lighter weight text layer of the info panel and copy the CSSHat generated code into a new mixin named PanelText:

.PanelText(){
color: #6b6b6b;
font-family: "Roboto";
font-size: 36px;
}

CSSHat to New Mixin, Larger Panel Text:

Now select the layer holding the thicker weight info panel text and copy the CSSHat generated code into a new mixin named UsingTheseText:

.UsingTheseText(){
color: #6b6b6b;
font-family: "Roboto";
font-size: 48px;
}

New Style:

Update the existing .panel style to:

.panel {
    max-width: 1200px;
	width:100%;
	margin: 0 auto;
	padding-bottom: 50px;
	text-align: center;
	.PanelBG();
	.PanelText();
	font-weight: 100;
	p {
		margin: 1.2em 0;
	}
}

This adds the PanelText mixin as well as a numerical font weight and some margin control for paragraphs in the info panel.

Also add the following new style code, below the .panel class:

.usingthese {
    //added font weight
	font-weight: 900;
	.UsingTheseText();
}

.highlight {
	color: #EF3D5C;
}

This applies the larger and thicker font styling to the bottom line of text, as well as adding colored highlights.

Result:

You should now see:

Add the Big Down Arrow

Add HTML:

Add the following code below your info panel:

<div class="downarrow"><i class="fa fa-arrow-down"></i></div>

Because we incorporated FontAwesome.less into our project earlier, this HTML will automatically place our down arrow simply via application of the classes fa and fa-arrow-down to an i (icon) element. 

At first it will appear in its default small, black state so all we need to do is style it as we would any other text element.

CSSHat to New Mixin:

In your PSD, select your big down arrow layer and copy the CSSHat generated code into a new mixin named DownArrow:

.DownArrow(){
opacity: .3;
color: #6b6b6b;
font-family: "FontAwesome";
font-size: 200px;
}

New Style:

Add the following new style code:

.downarrow {
    margin: 80px auto;
	text-align: center;
	i {
		.DownArrow();
	}
}

Result:

You should now see this below your info panel:

Starting the "Start" Button

Add HTML:

Add the following code below the big arrow html:

<div class="buttonrow">
<a href="https://webdesign.tutsplus.com/tutorials/photoshop-to-pure-code-with-csshat-and-pnghat-part-1--cms-20786" target="_blank">
<button class="start"><span class="arrowcircle"><i class="rightarrow fa fa-caret-right"></i></span>
Start the Tutorial
</button>
</a>
</div>

As with our down arrow, our use of the FontAwesome classes fa and fa-caret-right automatically place the icon we want to use, in this case a right pointing arrow.

CSSHat to New Mixin, Button Background:

In your PSD, select your start button rectangle layer and copy the CSSHat generated code into a new mixin named StartButtonBG:

.StartButtonBG(){
.border-radius(10px);
background-color: #ef3d5d;
.box-shadow(~"0 3px 0 #cc2241, inset 0 0 5px rgba(222,42,74,.6)");
.background-image(~"linear-gradient(bottom, #ee2c4f 0%, #dc2344 10.5%, #fc6b85 100%)");
}

Add Button Background Second Shadow:

Just as we did with the panel header, we'll now add a second shadow to the mixin we just created. 

In your PSD, select your button second shadow layer and copy only the code between the parenthesis on the box-shadow line:

0 5px 3px rgba(0,0,0,.27)

In the StartButtonBG mixin add a comma before the closing parenthesis of the existing box-shadow line, then paste in the code you just took from CSSHat to give you:

.box-shadow(~"0 3px 0 #cc2241, inset 0 0 5px rgba(222,42,74,.6), 0 5px 3px rgba(0,0,0,.27)");

CSSHat to New Mixin, Button Text:

Select the text layer of your start button and copy the CSSHat generated code into a new mixin named StartButtonText:

.StartButtonText(){
color: #fff;
font-family: "Roboto";
font-size: 36px;
text-shadow: 0 -1px 0 #b50020;
}

New Style:

Add the following new style code:

.buttonrow {
    text-align: center;
	margin: 20px auto;
}
.start {
	border: 0;
	padding: 0.75em 1em;
	display: inline-block;
	.StartButtonBG();
	.StartButtonText();
}

The first .buttonrow class acts simply to center the button, while the second .start class applies both the button background and text styling.

Result:

You should now see:

Button Circle and Right Arrow

In this case we don't need any extra HTML as we're working with the button HTML added in the last step.

CSSHat to New Mixin, Arrow Circle:

In your PSD, select the small circle layer over your button and copy the CSSHat generated code into a new mixin named ArrowCircle:

.ArrowCircle(){
.border-radius(23px);
background-color: #ef3d5d;
.background-image(~"linear-gradient(bottom, #ef4f6b 0%, #e32d4f 100%)");
}

CSSHat to New Mixin, Right Arrow:

Now select the small right-pointing white arrow layer and copy the CSSHat generated code into a new mixin named RightArrow:

.RightArrow(){
color: #fff;
font-family: "FontAwesome";
font-size: 36px;
}

New Style:

Add the following new style code:

.arrowcircle {
    display: inline-block;
	text-align: center;
	padding-left: 7px;
	margin-right: 10px;
	.size(47px);
	.ArrowCircle();
}

i.rightarrow {
	font-style: normal;
	display: block;
	line-height: 50px;
	.RightArrow();
}

Result:

You should now see:

Styling the Bottom Trim

Add HTML:

Add the following code below your start button HTML:

<div class="bottomtrim"><div class="centercircle"></div></div>

CSSHat to New Mixin:

In your PSD, select the layer that holds the two small concentric grey circles and copy the CSSHat generated code into a new mixin named CenteredCircle:

.CenteredCircle(){
border: 5px solid #ddd;
.border-radius(20px);
background-color: #f1f1f1;
.background-image(~"radial-gradient(center center, 100px 100px, #ddd 0%, #ddd 39.99%, #f1f1f1 44.75%, #f1f1f1 100%)");
}

Tweak the Radial Gradient Code:

This is the one place I found the CSSHat output didn't quite match what I had in the PSD. Change the mixin's background-image line, replacing center center, 100px 100px with center, ellipse cover like so:

.background-image(~"radial-gradient(center, ellipse cover, #ddd 0%, #ddd 39.99%, #f1f1f1 44.75%, #f1f1f1 100%)");

New Style:

Add the following new style code:

.bottomtrim {
    margin: 120px 0;
	height: 15px;
	border-top: 5px solid #ddd;
	border-bottom: 5px solid #ddd;
	text-align: center;
}

.centercircle {
	display: inline-block;
	margin-top: -17px;
	.size(40px);
	.CenteredCircle();
}

The first class .bottomtrim creates the two grey lines of our bottom trim, while the .centeredcircle class sizes and positions our concentric grey circles over the two lines.

Result:

You should now see this at the bottom of your design:

Wrapping Up

That's it! You should now have your completed static design in all its pure code glory, looking like this:

Extras

We've kept everything pretty simple for the purposes of this tutorial, but there's plenty more you can do with the code involved in this process if you prefer.

In some cases we've double up on styles by re-using font family declarations and colors, so you can define your font families and colors as variables and use those instead for easier updating later.

CSSHat also supports output in Stylus + Nib and Sass / SCSS + Compass, so if either of those are your preferred preprocessor you can try using those instead.








Advertisement