Friday, January 31, 2014

1stwebdesigner

1stwebdesigner


Learning SASS: A Beginner’s Guide to SASS

Posted: 31 Jan 2014 06:00 AM PST

Writing a lot of CSS can be overwhelming; that is why learning SASS and LESS can make  any web developer and designer’s life much easier. For a beginner, you might find it fine but as time goes by and your CSS skills are improving. You begin to wonder if there is a way so that you don’t need to repeat a lot of CSS codes in your style sheet. The good news is, there is one! Thanks to the CSS pre – processor, it's now possible to write concise CSS codes without repeating each of them again and again. It is even formatted nicely. You can perform computations and do dynamic styling using these pre-processing methods. There are two pre-processing methods that I will tackle: SASS and LESS. For this tutorial I will talk about SASS first and then on a separate tutorial, I’ll talk about LESS.

CSS Drawbacks

Using CSS only might work for you but when making big websites with multiple pages, there might be some features you wish CSS has. Take a look at the following disadvantages of using CSS alone.

  • No way to re-use common style rules.
  • No way to specify variables that can be defined and re-used all through the style sheet.
  • You can't execute computations where you can add numerical values to elements.

Advantages of Using Pre-Processing Methods

While using CSS alone might give you nuisance, using pre-processing methods can save you a lot of time and effort. Check out the list of advantages of using pre-processing methods below.

  • Allows you to use variables that can be re-used all throughout the style sheet.
  • Higher level style syntax that provides advanced CSS features.
  • Compiled CSS files are uploaded to the production web server.

What Is SASS?

SASS stands for Syntactically Awesome Style Sheets and was  designed and created by Hampton Catlin. SASS manipulates CSS using variables, mixins, inheritance and nesting rules. Given the extensions .sass and .scss respectively, it’s translated to well-formatted CSS using a command line tool or web-framework plugin.

SASS makes it easier to write less CSS codes and manipulate them dynamically. It’s a great way to write more functional CSS codes and can speed up the workflow of every web developer and designer.

.sass VS. .scss Format

Before we begin on how to use SASS, let's compare .sass and .scss extensions of SASS. First I will provide a simple CSS code and then I will show you how to simplify them on both extensions of SASS.

CSS Code

For our CSS, I used a header tag and put a zero value for margin and padding then white color for its text color.

    header {       margin: 0;       padding: 0;       color: #fff;  }    

.scss Extension Format (New Way of Writing SASS)

To format this into .scss extension format, we will use a variable $color and give it a hexadecimal color value of #fff for white color. And then under the CSS style, instead of putting a hexadecimal color value of #fff, use the variable $color that was set in the beginning of the code.

  $color:  #fff;  header {      margin: 0;      padding:0;      color: $color;  }    

.sass Extension Format (Old Way of Writing SASS)

For our .sass extension, we will have the same variable and value just like the .scss extension format, but, this time, without semi-colons and brackets. Notice that indentions are more reliant. This is the old format in writing SASS.

  $color: #fff  header     margin: 0     padding: 0     color: $color  

Resources you need to complete this tutorial:

Installing Ruby

Before you can be able to test how SASS works, you need to download Ruby to your computer. Launch the Ruby installer and you will be prompted with the Setup page. Select your preferred language and click OK.

1

Then click on I accept the License radio button. 2

Next, install it to your preferred location and make sure that the radio button for Add Ruby executables to your PATH is checked. Click the Install button. This will install the software and when it's done installing, just click the Finish button.

34

Checking if Ruby is Running Properly

Now that you have installed Ruby, let's go ahead and check if this is working properly. Open Command Prompt and type the word ruby -v. And you can see, it would return the current version of the Ruby installed along with the date. If it's returning an error, it could be that Ruby was not installed correctly or you did not put the Ruby executable into your path.

5

Installing SASS

To install SASS, open Command Prompt and type the word gem install sass and you can see that the Installation Prompt that it was successfully installed.

6

Preparing the Necessary Files

Before digging in with SASS, we need to prepare the necessary file you need before you code. Create a new folder to your preferred location (for this tutorial, I placed mine on my desktop) and name it SASS or any name you preferred. Inside the SASS folder, create an HTML file and name it index.html. For the HTML content put the following code.

    Introduction to SASS          	<link href="style.css" rel="stylesheet" type="text/css" /></pre>  <div id="container"><header>  <h1>Sass Sample Document</h1>  <h2>A 1stwebdesigner tutorial</h2>  </header>  <div>  Simple paragraph of text    Another paragraph of text</div>  <div>  <ul id="list1">  	<li>List Item 1</li>  	<li>List Item 2</li>  	<li>List Item 3</li>  </ul>  </div>  <footer>  <h3>This is a cool footer content</h3>  </footer></div>  <pre>    

Now for our SASS file, create a new blank file in your text editor and name it style.scss. If you followed the steps, by this time you will have the following file structure.

7

Converting SASS code into CSS code

To convert the SASS code into CSS code, we're going to use the -watch command in command prompt. This will compile the SASS codes to CSS. Additionally, this will also watch the directories for changes or updates. Let's try to convert  the SASS file to CSS file. Before we start, we need to put a sample code on our style.scss to see if this working.  Copy and paste the following sample SASS code on the stye.scss file you created under SASS folder.

    $myMargin: 0px auto;  $myColor: red;  $myWidth: 600px;    h1 {  	color: $myColor;  	$myMargin: $margin;  }    

Next, open your command prompt and then go to the location where you put your files in. In my case, I put it in my desktop so I will type in cd ”Desktop” and it will locate the desktop directory.

8

Now that we are in the desktop file directory, type in the sass –watch Sass:Sass 9

Using –watch command, we will convert all of the .scss files on the folder SASS. It will also watch for the changes or updates on the file. Notice that there are two SASS, divided by a colon. The first one represents the current location of the .scss file while the second one represents the location of the output of the file. Make sure you link the converted CSS file to your HTML file to see this working.

 10

Using Variables

SASS variables are declared using the $ character and are defined like CSS values. Using SASS, you can declare variables for styles like font size, margin, padding and so on. Using variables and giving it a style value makes it easy to reuse a style repeatedly.

There are six different types of variables you can use with SASS.

  1. Strings (e.g. $myString: “your text here”;)
  2. Numbers (e.g. $myNum: 10px;)
  3. Colors (e.g. $myColor: white;)
  4. Booleans (e.g. $myBool: true;)
  5. Lists (e.g. $myItemList: 1px solid red;)
  6. Nulls (e.g. $myVar: null;)

Let's put some of these types into practice. Open up your style.scss file and type the following code.

    $myColor: #009a82;  $myString: " some text here ";  $myFontSize: 13px;  $myMargin: 0px auto;  $myWidth: 460px;    h1 {  	color: $myColor;  	margin: 0;  	padding: 0;  }    #container {  	width: $myWidth;  	margin: $myMargin;  }    

Now when you run this code into your browser, you will have this output.

12

Nesting

SASS also allows you to define nested styles. This will let you write easy-to-read codes. For instance, you have the following CSS code.

  #container p {     font-family: Arial;     font-size: 13px;  }    #container h1 {     font-family: Tahoma;     font-size: 15px;  }    #container h2 {     font-family: Helvetica;     font-size: 14px;  }    

For the SASS version, you will have a format like this.

  $myFontsize1: 13px;  $myFontsize2: 18px;  $myFontsize3: 25px;  $myWidth: 500px;  $myMargin: 0px auto;    #container {      width: $myWidth;  	margin: $myMargin;    	p {  		font-family: Arial;  		font-size: $myFontsize1;  	}        h1 {  		font-family: Tahoma;  		font-size: $myFontsize3;  	}    	h2 {    		font-family: Helvetica;  		font-size: $myFontsize2;  }  }  

Notice that we put all of the elements styles under the id container, instead of naming them one by one under the same element. If you run this code into your browser, you will have something like this.

12

Mixins

Mixins let you define common properties once then re-use them over and over again. Mixins are defined using @mixin directive and contains a block of codes and then reuse them using @include directive. Let’s put this into practice. Copy the code below to your style.scss file.

  @mixin border {     border: 1px solid red;  }    #container {     width: 960px;     margin: 0 auto;     @include border;  }    

As you can see, we use the @mixins directive to create a style for border and then we include the style to id container using @include directive. If you run this in your browser, you will have the output below.

13

Operators

Performing mathematical operations is one of the best features of pre-processors like SASS, something which you can't do with just a normal CSS code. Given this feature allows you do more complex and dynamic codes. Let's take a look at this how it works. Go ahead and open your style.scss file and copy and paste the code below.

    $myColor: #aa30ff;  $myPadding: 20px;  $thickness: 1px;  $border: solid red;    #samplepara{  	color: $myColor;  	padding: $myPadding+30;  }    #list1 {  	color: $myColor;  	border: $thickness+5 $border;  }    

As you can see, we perform mathematical computations by adding 30px on the padding. We also added border thickness of 5px on the border. If you run this in your browser, you can see the output will look like this.

14

Functions

SASS offers a variety of functions. A good example of this is the color functions where you can manipulate color styles. Check out the series of color functions below.

  1. darken(color, amount)
  2. lighten(color, amount)
  3. saturate(color, amount)
  4. desaturate(color, amount)
  5. alpha(color)

These are just series of examples of functions. To learn more about functions check out the SASS documentation. For now let’s go ahead and try this example to see how SASS functions work. Open your style.scss folder and then copy and paste the code below.

    $myColor: #202020;  $myBackground: #e6e6e6;    body {       background: darken($myBackground, 20%);  }    h1, h2 {       color: lighten($myColor, 40%);  }    

Notice that the color darkens by 20% using the darken function while the H1 lightens, and also the H2 text by 40% using the lighten functions. So if run this in your browser you can see similar output below.

15

SASS Output Formatting

One of the best features of SASS is it offers several options to control how the .scss code is formatted when compiled into CSS. Using the -style option command, we can perform formatting to our compile CSS code. The following are the SASS formatting styles.

Nested Format

Nested style is the default format of SASS. This format gives indention to all of the styles in your compiled CSS file. To see this in action, copy and paste the code below into your style.scss and then open your Command Prompt (make sure you are inside the directory of SASS) and type in SASS –update style.scss . This command will update the formatting for the compiled CSS file using the update command.

16

 Now go ahead and open your compiled style.css file. As I've said above all of the styles will have proper indention.

  17

Expanded Format

This is the most user-friendly and readable format as the braces are properly expanded and each property will have its own line. Let's see this in action. Using the same code above, open your command prompt and type sass –update style.scss –style expanded. Notice that we added –style command this is used to format compiled CSS file to a particular formatting.

18

So if you are going to look at the compiled CSS file on the SASS file, you can see the code formatting is similar to the image below. Notice that each property has its own line. The braces are also fully expanded.

19

Compact Format

This is the compact format output CSS code in a condensed but still readable format. It adds spaces between braces but all in one line. To see how this works using the same code above, open your command prompt and type sass –update style.scss –style compact .

20

If you are going to check the compiled CSS file, you can see something similar to the image below. It is condensed. Each property and style is in one line.

 21

Compressed Format

The compressed format has minimized output. This is suitable for the production environment. This format has more condensed formatting. Using the same code, open your command prompt and type in sass –update style.scss –style compressed .

22

So if you are going to look at the compiled CSS file on the SASS file, you can see code formatting similar to the image below. As you can see, all codes are in one line with no spaces at all. 23

Conclusion

SASS offers a variety of ways to simplify your CSS issues. It allows you to reduce repetition of codes by using variables. SASS is powerful. This can help to improve the workflow of both web designer and web developers. Learn SASS now and discover how it can it help you build professional websites in a fast-paced development. Hope you enjoyed this tutorial and see you again next time.

Wednesday, January 29, 2014

1stwebdesigner

1stwebdesigner


How to Use UI Kits – Plus Free UI Kits to Choose From!

Posted: 29 Jan 2014 06:00 AM PST

UI kits can be seen anywhere on the Web. But what is this UI kit thing? Do you know how to use UI kits? You can see a lot of resources with beautiful interface elements such as buttons, sliders, breadcrumbs, media players, forms and the likes. Perhaps it crossed your mind how these elements came to be.

Let me give you first a brief introduction about UI kits. A UI kit stands for "User Interface Kit", which are PSD files that are composed of user interface elements. These come in a variety of colors, patterns and asl files that are being integrated on web and mobile designs. Though sometimes there are UI elements that are included on the package that you don't think you will be using. That being said, UI kits will vary according to your web design needs. Usually the premium versions of UI kits come with a lot of user interface elements than the free ones.

Using UI kits is all about improving and speeding up the workflow without giving a lot of time thinking what to design. This allows you to focus more on the functionality and usability of the website you are working on.

OK, enough for introduction. I know you're all fired up and want to know how to use UI kits. So let's rock!

Choosing a UI Kit to Use

There are a lot of UI kit resources on the Web that you can use, depending on what you need. But for this tutorial, we will be using Flat UI PSD format by Designmodo.com since it has a lot of user interface elements that we can choose from.

Feel free to check these out too!

Flat UI Pro, a professional design framework

1.  Flat AP UI Kit

From: Andrew Preble
free-flat-UI-kit-1

2. Featherweight UI – A free, vector based and retina ready UI kit

From: Sara Hunt
free-flat-UI-kit-2

3. Flat Design UI Kit Vol. 1

From: Bloom Web Design
free-flat-UI-kit-15

4. FREE flat UI kit.

From: Visualcreative.cz
free-flat-UI-kit-4

5. UI Kit

From: Abhimanyu Rana
free-flat-UI-kit-5

Opening the UI Kit PSD File

Unzip the file first to view the contents of the folder. You can see four folders and 2 .txt files inside. Open the UI folder and then view the flat-ui-free.psd file in Adobe Photoshop.

file-structure

photshop-opened

By default, there are three folders on the Flat UI PSD file:

  • Basic Elements – consists of a series of individual UI element folders.
  • Samples – consists of the actual application design of the UI elements.
  • Background – the white background of the UI elements.

psd-file-structure

Using the UI Kit Elements

Now that the Flat UI PSD file is opened, we can now go on and use the UI elements. Click Auto Select on the Option Bar (on the top left section of Photoshop near the menu. Make sure Group is selected instead of layer) and then open the Basic Elements folder.

auto-select

open-basic-element

Next, select the UI elements that you want to use. For this example, we will select the menu, share status buttons, radio buttons and checkboxes. Click on the selected UI elements and then move them to a new Photoshop document file.

menu-ui

Resizing UI Kit Elements

To resize UI elements, click on the Direct Selection Tool on the toolbar on the left section of the Photoshop.

direct-selection-tool

And then select the path on the right side of the UI element you want to resize. For this example, we will resize the menu element, press shift and drag the path to the right to resize.

resize

Changing the UI Element Color Scheme

To change the color scheme, you need to select the specific element you want change then click on the shape and select your preferred color on the color picker. For this example, we will change the background color of the menu. Go to the Menu folder and look for the shape layer that has the same background color of the menu. Change the background color of the menu to hexadecimal color: #00acc0.

change-color

Using Vectors and Glyphs

Vectors and glyphs add a touch of  creativity to web design elements. Let's use the existing vectors and glyphs of the Flat UI kit. Create a new Photoshop document file. Next, create a box using Rounded Rectangle Tool with the dimension of 372px by 372px.  Now drag the retina vector icon and static green button on the box you created. Then drag the round check icon glyph to the left of the static green button. You just use the vectors and glyphs of UI elements.

vector-glyphs

Exporting UI Elements for Web

Now that we already know how to resize and change the color scheme of UI elements, let's export them for web use. Simply drag your preferred UI element in the new Photoshop document file with a transparent background. Make sure you will only select the layers of that UI element, not the whole folders themselves. For this example, let's use the paginator. Drag the UI element in the new Photoshop document and go to Image then choose Trim.

trim1

The Trim window will then appear. Next, select the Transparent Pixels radio button and make sure that all of the checkboxes are selected on Trim Away section (Top, Bottom, Left, Right) and then click OK.

trim2

Then Go to File > Save for Web & Devices. In the Save for Web & Devices Window, select the type of preset you want to use. For this example, PNG-24 is used since high quality image with no transparent background is preferred. Click Save to place it on your preferred location.

save-for-web

Congratulations! You just learned how to use, resize, change color scheme, apply vectors and glyphs and export UI kit elements for web used.

Conclusion

UI kits are very helpful to both web designers and web developers. If you are a freelancer, using UI Kits will save you a lot of time since you don’t need spend more time thinking for the design. It can please your clients too because you can deliver the project faster. You can explore more UI kits here. The web is composed of hundreds of UI Kits, both in free and premium versions. You just need to choose the UI kit that suits your needs. You might also want to try to apply it on your actual web or mobile design and then later on code it using HTML and CSS.