View Single Post
Old 07-10-2007, 09:08 AM  
ServerGenius
Confirmed User
 
Join Date: Feb 2002
Location: Amsterdam
Posts: 9,377
Quote:
Originally Posted by StuartD View Post
One of the best advantages to CSS is to programmers.

5. CSS for programmers

CSS makes a slick looking web page, but more importantly, it will greatly simplify your PHP/other code.

Imagine if you will, a gallery that has 15 thumbs in it. You can have your code create a row <tr> and then so many <td>s and then another <tr> at $rowcount=5; and then another <tr>.... and so on. And figure out when to do your ifs and elses.... it's a pain to do something simple.

Now imagine that in CSS, you created a div that's 700px width. So far so good.

Now you can have each thumb set up like this:
<a href='fullsize1.jpg'><img src='thumb1.jpg' class='thumb'></a>
<a href='fullsize2.jpg'><img src='thumb2.jpg' class='thumb'></a>
<a href='fullsize3.jpg'><img src='thumb3.jpg' class='thumb'></a>
...
...
so on.

And CSS the thumbs to float: left;
.thumb {
float: left;
}

Now the thumbs will go next to each other side by side, and wrap on their own down a row once there is not enough room. So you can change the size of your containing div to 500px if you want, and the thumbs will just know what to do on their own!! They'll wrap at a different thumb!

Want to space the thumbs? padding: 5px.
.thumb {
float: left;
padding: 5px;
}

Simple right? Now apply this to your code. Instead of doing the math to figure out when <tr>s start and end.... we just have a simple loop that does all of the images in a stardard output. The CSS does the rest.

This applies to many things, including menu options, lists... what have you.

Your PHP will be simplified once you don't have to figure out where in the code to put counters to track when to enter an HTML element.
same strategy works to define colors, fonts, backgrounds/colors, table styles
form styles....that way you can keep all html basic and do all the styling with
seperate css.files which you include in the head part of the html
__________________
| http://www.sinnerscash.com/ | ICQ: 370820 | Skype: SinnersCash | AdultWhosWho |
ServerGenius is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote