Tuesday, May 10, 2011

CSS Back to basics: Here comes TRBL

So I guess CSS is not obvious to everyone. One of my coworkers asked today why you sometimes had 1 value after a "padding" attribute and sometimes you had 2 or 4 values.

Basically,


padding: 5px;

Puts a 5 pixel padding on an element.


padding: 5px 3px;

Means you have 5 pixels of padding on the top and bottom and 3 pixels on the sides


padding: 3px 4px 5px 10px;

Means you have 3 pixels of padding on top, 4 on the right, 5 on the bottom and 10 on the left.

A good way to remember this is the acronym TRBL (like "trouble").

The same applies to "margin".

As well as this, you also have extra attributes which can specify the top, bottom, right and left paddings on their own

i.e.

padding-left: 10px;


Sometimes, if only one side is unique, it's better to refer to it in the following way (for readability).


padding:5px;
padding-left: 10px;

The "padding-left" of 10px will override the "padding" of 5px, but only on the left side of the element.


padding: 5px 5px 5px 10px;

The above does the same, but is less readable in my opinion.

6 comments:

web design perth said...

It took me awhile to grasp the CSS basics and the meaning behind each script line. I advise on understanding them line by line on how they affect one another.

seo reseller said...

It's always good to know the basics. CSS can be a complicated one if you don't have any background about it. This is very important in starting a blog or website because CSS is a part of SEO strategy and techniques.

George Schneider said...

This simple tutorial clarified the things about the usage of 1 or more values on CSS. CSS basics are important to make a meaningful, compelling and eye-catching web design.

Anonymous said...

Learning the basics of CSS is really not that easy. You have to understand it line by line and how they function with one another. But it will be all worth it if you master it.

seo services said...

I agree with the comments. It is indeed important to have a full grasp of the basic and fundamental concepts to ensure its functionality. A simple dot or comma can affect the entire picture of the design.

Website Development Portfolio said...

I'm impressed. You're truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. I'm saving this for future use.