Make your css reusable

Author: Ben  |  Category: Web Design

A lot of New Web Developers usually rewrite all the CSS when they need to redesign or update the current web template, and that is really not efficient at all.? So, how can we minimize the amount of time that have to be spent on the CSS?? The answer is simple.? Make your css reusable. But how?

Now, we start from the basic CSS elements.

.bold{

font-weight: bold;

}

.underline

{

text-decoration: underline;

}

and so on…

So whenever you want to make your text bold or underline you can do

<span class=’bold’>bold this</span> OR <span class=’underline’>underline this</span>

So far, it is still the basic, and nothing is really exciting right?

Ok, let’s make it a little bit complicate by introducing the multiple class names.

Now, suppose you want to make your text bold and underline.

Usually you would do

.bold_and_underline

{

text-decoration: underline;

font-weight: bold;

}

then finally apply it to the html tag like this <span class=’bold_and_underline’>bold, underline</span>.

If you are going to mix and match different css properties to the html element, you will end up with write a lot of css properties, and a lot of them just keep repeating.

By using multiple class name, now you can make your life a little bit easier.

You can do this:

<span class=’bold underline’>bold and underline</span>

If you want to apply more properties to the HTML Tag, you can always mix and match of your basic css properties by using the multiple class names.

And I would recommend you to make your class names more meaningful, so you can remember it when you apply it to your html tags.

However, this is not the end yet, and we can even go further with the classes.

A lot of web template will have a lot of <div> containers with css properties, such as, float: left, margin: 0, padding: 0;

Now, let’s set this up in css.

.container

{

margin: 0;

padding: 0;

float: left;

}

and assume we have two div tags, such as

<div class=’container big_box’></div>

<div class=’container small_box’></div>

And now, let’s see the properties of the big box and small box,

.big_box

{

width: 300px;

height: 400px;

}

.small_box

{

width: 100px;

height: 100px;

}

Now, you can see that it save you from writing the margin, padding, float properties repeatedly.

Without the multiple “class names”, you will have to do this:

.big_box

{

width: 300px;

height: 400px;

margin: 0;

padding: 0;

float: left;

}

.small_box

{

width: 100px;

height: 100px;

margin: 0;

padding: 0;

float: left;

}

Finally, the multiple “class names” is compatible with IE6,7, firefox, opera, another other major browsers, so you can feel safe to use it for your projects.

Good luck.

Reduce HTTP request

Author: Rockia  |  Category: Web Design

I made a review on my coding style today and I found that I made a big mistake.

I always made a folder called “JS” and “CSS” when I first start scatching a website from blank. And I will put all different .js and .css files insides. For example, if I have 3 pages called “aboutus.php”, “main.php” and “jobs.php” in my website, I will put at least 3 different CSS files into the CSS folder; well, they will be mostly called “aboutus.css”, “main.css” and “jobs.css”. For certain of time, I found this very useful, like when I need to change the style of some elemetns under “main.css”, I can just look under the “main.css” and I don’t have to scroll the whole “css.css”.And ALL of these are stored in the files call “top.php” that will be contained in each pages.

However, I found this is a big problem today. IT INCREASE THE TIMES OF HTTP REQUEST!!!

OK, I guess no one will have the “style” in each different elements nowadays when we are going to write out the whole site. Most people, I will say 99.99%, will have the .css files as external links outside of the page. And example will be:

<link rel="stylesheet" href="css/index.css" media="screen"/>

Actually, when the browser loads this website, and it “sees” this line, it will make a request to the server for this “css/index.css” file. Here the first time. Like I said, if I have 3 different files, the browser will actually make 3 request to the server. This might not sound too bad. However, if I have another 3 .js files there. Then for each page, it will at lease send 6 requests to the server for all these external files before the page <body> tag was load; yes, that means, before you see anything on your screen, the server has 7+ requests already. Plus, there will be some more requests for the images and all different other medias (I will talk about those later on.)

Let’s say, if you only have 1 picture and 2 divs in your page, then your browser will make at lease 10 requests, and 6 of them were made before your page was displayed. And I have 3 pages, if the person is interested in my site and he/she wants to read all of these, then there will be 18 requests before pages’ content was loaded.

If we merge all these .css files into one, and all the .js files into one .js. We can save 2/3 of the requests in this case before the page content is loaded.

100% Pure CSS menu

Author: Rockia  |  Category: Web Design

http://www.opencube.com/index.asp

Can’t believe such a professional menu can be created by just several simple clicks.

It’s a commercial software, but hey, it’s great. You can go ahead to take a try using the online interface first.

Also they have tons of web effects as well. Check it out, and you don’t want to miss it.