• Home

Logo

Navigation
  • Home
  • Articles
    • Content Writing
    • Design
    • General
    • Internet Marketing
    • Social Media
    • Tools and Tips
    • Usability
    • Web Hosting Articles
  • Tutorials
    • AJAX Tutorials
    • ASP Tutorials
    • C# Tutorials
    • CGI and Perl Tutorials
    • CSS Tutorials
    • Flash Tutorials
    • HTML Tutorials
    • Illustrator Tutorials
    • Java Tutorials
    • JavaScript Tutorials
    • Linux Tutorials
    • Miscellaneous Tutorials
    • MySQL Tutorials
    • Photoshop Tutorials
    • PHP Tutorials
    • Python Tutorials
    • Wireless Tutorials
    • WordPress Tutorials
    • XML Tutorials
  • Scripts
    • AJAX Scripts
    • ASP Scripts
    • ASP.NET Scripts
    • CGI & Perl Scripts
    • Flash Scripts
    • Java Scripts
    • JavaScript Scripts
    • PHP Scripts
    • Python Scripts
    • Remotely Hosted
    • Tools and Utilities
    • XML Scripts
  • Answers
  • Online Services
  • Tools

Four CSS Tricks Every PHP / Web Developer Should Know

By Akash Mehta | on May 31, 2008 | 6 Comments
CSS Tutorials PHP Tutorials
CSS Before
  • Tweet
  • Share
  • Tweet
  • Share

It’s not easy being a web developer – in addition to a server-side language, we also have to learn a markup language, yet another (client-side) language and a presentation system. As a result, we tend to focus on what we’re closest to – the business logic – and neglect the front-end.

But you don’t have to be a web dev guru to build great applications: with just a few simple tricks, you can make your web based interfaces more usable and more visually appealing. Here are a few simple CSS tricks every PHP / web developer should know.

twilight divx

Here’s a quick preview of how we’re going to transform our page:

1. Styling Form Inputs, Buttons
When you pop an <input> onto your page, it’s at the mercy of the end user’s system for appearance, behaviour – even size. For example, Firefox handles unstyled inputs differently from IE, and both take many cues from the local OS styling; the same goes for Safari. This is okay on modern OSes — if you aren’t concerned with controlling your visuals — but quite a few users still run “Classic” interfaces, and it’s especially annoying for buttons. Here are some basic styles you should consider for your inputs.

input {
	padding:3px;
	border:1px solid #F0F0F0;
}

These will first add a bit of padding to your text boxes and buttons, and set in stone your border color to a soft gray. In particular, most browsers will render a clean rectangular button with this style present. Consider defining a width in pixels or percents (if inside a container) as well.

2. Styling Tables
Remember to style tables nicely, with table row hover colors, reasonable borders and maybe even striped tables. After all, tables can be dull and boring:

Heading 1 Heading 2
Value Value
Value Value

There are two key areas to this: using semantic markup, and taking advantage of CSS selectors. Let’s first fix up our table HTML:

Heading 1 Heading 2
Value Value
Value Value

And then add some styles:

table {
	border-collapse: collapse;
	border: 1px solid #CCC;
	font-size: 12px;
}

table thead td {
	font-weight: bold;
	background: #E1E1E1;
}

table tbody tr:hover td {
	background-color: #F3F3F3;
}

table td {
	padding: 5px 10px;
}

First, notice the use of border collapse – this prevents the blocky double-borders on cells. Next, we take advantage of our <thead> and <tbody> to apply a background color to our header row, but a hover effect on body rows. The :hover is on the table row, but the actual background needs to be applied to the cell. Finally, we add a neat padding that keeps text in order. A smaller font size on your table will also cut it down to size and fit more figures on a page.

3. Button Links
Often you want a button-style link to execute a simple action or lead the user to another page. Let’s create a simple “Next” link with this markup:

Next »

We can then style it nicely with this CSS:

a.button {
	background: #AAA;
	color: #FFF;
	padding: 3px 5px;
}

a.button:hover {
	background: #888;
}

We first set a simple background color on the anchor to make it stand out, and ensure the text is still visible. However, feedback is important here – by adding a simple hover color, we make it clear that this is an interface element and not some ordinary link.

4. Typography
It isn’t hard to use simple, clean text on your pages, as opposed to the serif-heavy fonts IE and Firefox will default to on Win/Linux. Try adding this to your main stylesheet:

body {
	font-family: Arial;
	font-size: 95%;
}

Arial isn’t terribly fantastic, but it isn’t too bad either. (Verdana is also a standard option.) By explicitly setting a font here, you avoid leaving at the mercy of the browser/OS, especially when you may not have testing machines of a particular OS available (e.g. OS X).

With all these techniques in play, we have a nice and usable interface:

Share this story:
  • tweet

Author Description

6 Responses to “Four CSS Tricks Every PHP / Web Developer Should Know”

  1. July 31, 2008

    Christian Fuentes Log in to Reply

    Great article, but I’d like to point out that the thead section should have and tags (not tags).

  2. July 31, 2008

    Christian Fuentes Log in to Reply

    well I forgot to put the html code in a way everyone sees it,

    the thead section should have <tr> and <th> tags (not <td> tags).

  3. July 31, 2008

    Akash Mehta Log in to Reply

    A valid point Christian – we could definitely have used <th> tags. However, browsers handle th’s specially as well (and inconsistently). It’s also easy to forget to style a th by defining a CSS rule on “td”. While I considered putting them in, it’s often easier just to put td’s inside the thead and style them accordingly.

  4. October 16, 2008

    sanath Log in to Reply

    Cool trick full of standards, that every designer should know.

  5. November 20, 2008

    Mexabet Log in to Reply

    Thanks for this post. I sometimes get entangled with this.

  6. May 15, 2009

    tukang nggame Log in to Reply

    a nice tips, thanks so much

You must be logged in to post a comment.

Connect With Us

RSSSubscribe 1,241Followers 493Likes
  • Popular
  • Recent
  • Comments
  • Creating Energy Spheres in Photoshop

    Apr 15, 2008 - 96 Comments
  • Easy Screen Scraping in PHP with the Simple HTML DOM Library

    Aug 6, 2008 - 20 Comments
  • Calculating date difference more precisely in PHP

    Mar 7, 2008 - 13 Comments
  • When Does Hosting Your Website in the Cloud Make Sense?

    Oct 8, 2010 - 2 Comments
  • Fun with the Microsoft Managed Extensibility Framework Part 2

    Oct 6, 2010 - 0 Comment
  • Fun with the Microsoft Managed Extensibility Framework Part 1

    Sep 22, 2010 - 0 Comment
  • Website Management on the go with the iPad

    I appreciated your post, but I was looking for something I didn't...
    November 24, 2012 - drmoderator
  • Creating Energy Spheres in Photoshop

    I'm a little stuck down here especially at the step of creating the...
    November 23, 2012 - sarah
  • Running background processes in PHP

    Can you give an example? As see it, you can use this only when you...
    November 16, 2012 - Shaked Klein Orbach
Developer Resources
  • Tutorial Directory
  • Learn HTML
  • Learn PHP
  • Learn CSS
  • Learn AJAX
  • Learn JavaScript
  • Learn Pear
  • White Papers
  • Resources
    • NetVisits Web Directory
    • Realtor Pixels
    • Answers On The Run
    • Ask A Geek
  • Recent Posts

    • When Does Hosting Your Website in the Cloud Make Sense?
    • Fun with the Microsoft Managed Extensibility Framework Part 2
    • Fun with the Microsoft Managed Extensibility Framework Part 1
    • Website Management on the go with the iPad
    • Code Contracts in C# 4.0 – Part 1

    Calendar

    May 2013
    M T W T F S S
    « Oct    
     12345
    6789101112
    13141516171819
    20212223242526
    2728293031  

    Recent Comments

    • drmoderator on Website Management on the go with the iPad
    • sarah on Creating Energy Spheres in Photoshop
    • Shaked Klein Orbach on Running background processes in PHP
    • Thomas Cuvillier on How To Upload Files Using PHP
    • rizal aditya on Extracting text from Word Documents via PHP and COM
    • Home
    © 2003 - 2013 DeveloperTutorials.com. All Rights Reserved. Privacy Policy.