Code2Design.com

User login

The Layout

Programming

Graphic Design

Resources

Navigation

C2D Projects

Unsystematic Affiliates

Open Web Design Pixel Digest pixel-efx Project 62 

Change Language

Who's online

There are currently 0 users and 7 guests online.

Understanding CSS Dimensions

If you have ever taken a dive into the CSS code of a layout you liked - only to find something like this:

.object {
margin: 0px auto 20px .8%;
padding: 0em 25px;
}

Then this tutorial is for you - because today I am going to explain the strange dimension system built into CSS! :)

Now first off, how many of you have ever be at a lost as to the direction you were going? Or have to think for a minute to figure out where West is from North? Even more to the point - how many of you have ever heard the old saying "Never Eat Soggy Waffles"? (No, quite that! - I didn't make it up!) Well, for all us humans without GPS systems - this saying stands for "North East South West" which is the clock-wise order of the directions.

---N---
W-----E
---S---

Well, CSS also uses the clockwise order of directions. Take a look at the following code:

When you see something like:

.object {
padding: 10px 25px 5px 0px;
}

If it were in English it would say:
.object {
padding (is): 10pixels(top) 25pixels(right) 5pixels(bottom) 0pixels(on left);
}
.object {
padding (is): 10pixels(North) 25pixels(East) 5pixels(South) 0pixels(West);
}

So just remember that the first element is the top (North) dimension and the rest can be found be saying "Never Eat Soggy Waffles". Now, CSS also has built in pattern recognizers. For instance look at the following code that only seems to cover the padding for the top and right of ".object".

.object {
padding: 10px 25px;
}

So what is the padding for the left and bottom of ".object"? Well, it is 10pixels on the bottom and 25pixels on the left. The computer automatically assumes that if you don't enter all the dimensions it should just keep repeating the pattern to fill in the remaining spaces. So to the computer, the above code would look like this:
.object {
padding: 10px 25px (10px 25px);
}

Just like you can type the first three values of a HEX number "color: #fff;" (white) and the computer will recognize it as the full 6 digit HEX number "color: #ffffff;" (white) - you can also type "padding: 5px 10px;" and the computer will see it as "padding: 5px 10px 5px 10px;". The computer will even read just one value and fill all remaining values with that number!
.object {
padding: 10px;
}
Would mean this to the computer:
.object {
padding: 10px (10px 10px 10px);
}

So, hopefully you can use this tutorial to help you better follow the code of CSS champs. :)


Submitted by David on April 17, 2007 - 7:24pm. |
printer friendly version

good tutorial

Great tutorial. That really made a lot of sense. Now, if I could only find those kind of tutorials for everything else...


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <br> <br /> <h3>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use BBCode tags in the text, URLs will be automatically converted to links
More information about formatting options



Like what you see?

Why not add more? C2D is looking for other Christian Web Masters who would like to help write articles for this site. If you have expericance in FLASH, CSS/HTML, PHP/MySQL, PhotoShop/GIMP, Blender, Javascript, or just General Design - our users would love to hear what you have to say. Contact Us

delicious   digg   reddit   magnoliacom   newsvine   furl   google   yahoo   technorati