Sep
3rd

CSS DO's and DON'Ts – Part III

Posted by Ashley on September 3, 2008 at 1:36 pm

Welcome to the third installment of CSS DO’s and DONT’s, a monthly blog series designed to provide useful, time-saving CSS tips while making note of some bad habits website developers tend to repeat in their code, despite the negative impact on workflow.

Today’s DO’s and DONT’s:
DO Properly Organize Your CSS File
and
DON’T Overuse Conditional Comments and CSS Hacks.

Let’s get started.

css

DO Properly Organize Your CSS File

Below are a few stylesheet layout and setup tips that can help to keep your workflow organized from initial planning and development to implementation and maintenance:

1. Hierarchy Management

You can layout your CSS in any order that best suits your own personal workflow style, but it is highly beneficial to develop and maintain a system that you can carry out consistently from project to project. The following list is a fairly common group breakdown among developers, and works well as a first tier organization system:

* Reset Styles
* Global Styles (body, paragraph, lists)
* Colors
* Layout and Structure
* Navigation
* Headers
* Text Styles
* Images
* Tables
* Forms
* Misc Styles

Also, don’t forget to flag each first level section with comment separators for easier future reference:


/* ———————————-*/
/* ———-GLOBAL STYLES———–*/

Global Styles Here

/* ——-END GLOBAL STYLES———–*/
/* ———————————–*/

2. Shorthand CSS

You can vastly minimize the amount of code in your stylesheet by learning to write shorthand CSS.

The following two property declarations actually accomplish identical styling outputs, even though “this” class only uses 4 lines of code versus the 14 lines of code in “that” class:

#this {
margin: 1px 5px 1px 5px;
font: bold 11px/16px Arial, Verdana, sans-serif;
border: 1px solid #cecece;
background: #fffff url(bg.gif) no-repeat;
}

#that {
margin-top: 1px;
margin-right: 5px;
margin-bottom: 1px;
margin-left: 5px;
font-weight: bold;
font-size: 11px;
line-height: 16px;
font-family: Arial, Verdana, sans-serif;
border-width: 1px;
border-style: solid;
border-color: #cecece;
background-color: #fffff;
background-image: url(bg.gif);
background-repeat: no-repeat;
}

Keep in mind that when using shorthand to set varying margin or padding properties for each side, the order of declaration is top, right, bottom, and left; i.e. “1px 2px 3px 4px;”.

Read the rest of this entry »

GD Star Rating
loading...

Socialize This Post

If you enjoyed this post, make sure you leave a comment.
Jul
11th

CSS DO's and DON'Ts – Part II

Posted by Ashley on July 11, 2008 at 9:25 am

Welcome to the second installment of CSS DO’s and DONT’s, our monthly blog series designed to provide useful, time-saving CSS tips while making note of some bad habits website developers tend to repeat in their code, despite the negative impact on workflow.css miami by geirarne

Today’s DO’s and DONT’s:
DO Comment a Reference Guide into Your CSS File
and
DON’T Forget to Validate Your Code.

Let’s get started.

DO Comment a Reference Guide into Your CSS File

When you’re deep into the code of any given website, you’ve probably memorized every hex color used in your design and are able to rattle off style values at will, even from a sound sleep. Flash forward to three months after launch and try to remember what the hex is for that sole yellow sidebox four pages deep. Unless you have a photographic memory, chances are you won’t remember!

Taking a few extra minutes to comment a style guide at the top of your CSS file could very well turn out to be your own most useful resource down the road. Rather than having to scan 500 lines of code to locate your yellow hex, you could readily locate it at the top of your document in a matter of seconds.

Style reference guides are also particularly beneficial to those working within a team setting of any kind, whether agency, in-house or virtually scattered across the globe. Even if only one team member is responsible for the markup of a website, the programmer on the team will find the guide handy when they need to style a report, while the graphic designer may reference the guide to pull colors for a custom icon set.

An example of a reference guide outlining the basic color scheme used in the website:

/* COLORS
blue #0033cc
light gray #efefef
navy #330066
orange #d97510
*/

Or, you can break it out by element:

/* COLORS
container #aeaeae
container border #333333
nav bg #330066
nav hover #d97510
image thumb border #176f77
image thumb border hover #275c61
*/

You can even take it a step further by including other style values, such as border or div widths. The more detail you provide, the handier your reference guide becomes:

/* VALUES
container #aeaeae 900px
container border #333333 1px solid
nav bg #330066 125px
nav hover #d97510
image thumb border #176f77 1px dotted
image thumb border hover #275c61 2px solid
*/

There are no set rules for marking up your reference guide in any particular way – just make sure you use a format that meshes well with your own semantics and workflow!

DON’T Forget to Validate Your Code

Although validating your code might seem like an extra step, especially when everything is rendering properly on all major browsers, here are a few thoughts to ponder:

1. Error-free code renders faster, meaning less download time for your website visitors.

2. Some search engines cannot properly index XHTML/HTML that contains serious errors.

3. Just because your code renders properly on all browsers this month, doesn’t necessarily mean that it will render properly with the next release of a major browser. Most browsers are becoming more standards compliant with every version release.

4. Browsers that are currently under development are probably being written in compliance with the World Wide Web Consortium’s (W3C) set of standards – validating your code now will protect your website from future browser incompatibilities.

5. Publishing valid code is a positive reflection of your abilities and attention to detail.

6. Unless your code has some serious issues, validating both your XHTML/HTML and CSS is a fairly quick task. Conversely, if your code does have serious issues, your company or client would probably greatly appreciate you going the extra mile to fix said issues.

If you’re a Firefox user, there are a number of extremely useful extensions that allow for one step XHTML/HTML validation. I prefer to use Marc Gueury’s HTML Validator. It puts a handy icon in your tray that you can click while viewing your development progress to pop open an organized three pane window displaying your code, page errors, and a useful help section, as shown in the screen shot below:

HTML Validator screen shot

Once you have fixed your XHTML/HTML errors, pat yourself on the back for a job well done and move on to validating your CSS.

The W3C also offers a free CSS validation service that is quick and easy to use. Simply input your website address, and in seconds you are presented with a breakdown of your CSS errors and warnings. Typically, errors are flagged when there is an improper value attached to a particular property, whereas warnings are generated to flag potential code issues such as a background-color value and color value that are the same for a single property.

Up Next Month: DO Properly Organize Your CSS File and DON’T Overuse Conditional Comments and Hacks.

You can catch up on our series by reading last month’s CSS DO’s and DON’Ts.

Image: geirarne

GD Star Rating
loading...

Socialize This Post

If you enjoyed this post, make sure you leave a comment.
Jun
6th

CSS DO's and DON'Ts

Posted by Ashley on June 6, 2008 at 12:13 pm

Welcome to the first installment of CSS DO’s and DONT’s, a monthly blog series designed to provide useful, time-saving CSS tips while making note of some bad habits website developers tend to repeat in their code, despite the negative impact on workflow.

Today’s DO’s and DONT’s:
DO Create a reset.css file and DON’T use Inline CSS Styling in Your Markup.

css vinyl by tiagonicastro
Image: tiagonicastro

DO Create a reset.css File

Cross-browser compatibility is a well-known term and largely-discussed topic among web developers and programmers. For the non-developer and average internet user, the term means absolutely nothing until the day they decide to switch (or upgrade, as some might argue!) their internet browser from Internet Explorer (IE) to Mozilla, only to discover that their favorite website or blog looks vastly different in the new browser.

As long as the differences weren’t evident enough to hinder the usability of the site, such as shifting the navigation menu outside the browser viewing area, the user would probably just chalk it up to a design update and continue on with their daily read. Developers and programmers, however, would immediately recognize these layout shifts as the result of inconsistencies among internet browsers’ default property values.

The World Wide Web Consortium (W3C), an “international consortium where Member organizations, a full-time staff, and the public work together to develop Web standards,” has been encouraging software companies to produce standards-compliant web browsers since 1994. The idea behind the W3C mission is solid; if they can convince browser vendors to adhere to a specific set of default value standards, the layout issues associated with inconsistent default styling values are resolved. However, with 100+ web browsers available to the public, the major players being IE, Firefox, Safari and Opera, the W3C has a lot of people to convince!

With no immediate relief in sight, web developers and programmers are forced to find alternative solutions to combat these never ending cross-browser compatibility issues to ensure that the websites they publish remain consistent in appearance across all browsers.

One effective and time-saving solution is to implement a set of CSS styles that imitate full cross-browser compatibility by setting the default property values of all browsers to a matching state. This allows the developer to begin their markup without having to battle initial styling discrepancies. It should be noted that in using this solution, developers will not be able to rely on any default values—even your <li> margin values will need to be specifically declared in proceeding styles.

Eric Meyer, author of “Eric Meyer on CSS”, has developed a set of reset styles that are free for public download or copy at Reset Reloaded. The list is quite extensive and absolutely thorough; however, feel free to add or remove reset styles to suit your personal development needs.

DON’T Use Inline CSS Styling in Your Markup

Imagine a situation in which your boss or client requests a universal color change on their 100+ page website—with a two-day turnaround. Back in the day when <font> tags were a developer’s only styling option, this would have been an impossible request to fulfill—unless, of course, you fully trust the Find and Replace tool. Today, however, this seemingly impossible task can be completed in five minutes or less, as long as the website is utilizing CSS to its full potential.

There are three ways to apply CSS styles to your markup: inline, embedded, and external. Inline styles are wrapped around your markup, no differently than the way <font> tags were applied in the early 90’s. In order to style all of your paragraphs consistently using inline CSS styling, you will need to apply the same code around or within every <p> tag in your markup. This is simply an impractical and cumbersome method for styling your markup.

Embedded CSS styles are placed between the <head> tags of your document and, although this method is a slight step above inline styling as it keeps the CSS code out of your markup, these styles need to be included between the <head> tags of every page within your website file structure. If you are dealing with a 100 page website, you will need to open, edit, save AND upload each and every file in order to implement a universal styling change. Again, impractical and cumbersome.

External style sheets are files that are completely independent of your (x)HTML files, and can reside anywhere within your website structure as long as the file path is properly referenced from your (x)HTML files. The use of external style sheets allows a developer universal control over their website—and this control goes beyond basic color and font changes. If the CSS is properly structured and the markup is clean, a complete redesign within a day or two isn’t completely out of the question! Additionally, calling your CSS externally means less code for a search engine’s web crawler to process.

So before you apply that inline style, consider this: Even though you’re under deadline and need a quick fix, the number of applied quick fixes will add up in a hurry and greatly hinder your ability to implement universal styling changes in the future.

The Bottom Line: Inline styling will inevitably create unnecessary work for the developer at some point down the road—and who has time for that?

Up Next Month: DO Comment a Style Reference Guide into Your CSS File and DON’T Forget to Validate Your Code.

GD Star Rating
loading...

Socialize This Post

If you enjoyed this post, make sure you leave a comment.
Dec
8th

All In a Week's Work in SEO: Sitemaps, DNS, CSS & Internet Explorer

Posted by Teal on December 8, 2006 at 4:31 pm

As an SEO, I am continually looking for ways for my clients to improve their overall visibility as well as increase usability – two very important issues for an effective online marketing strategy. There are three topics I would like to speak briefly about in this post: sitemaps (not Google Sitemaps) but real old-fashioned sitemaps that are supposed to be a helpful resource for users as well as search engines to find all of the pages on a site, how a DNS setup really can have an effect on search engine positioning and indexing, and finally CSS – a somewhat new and wondrous language to me – and the issues that arise from its use in Internet Explorer 6.

Sitemaps
Simply put, a sitemap is a way to provide users and engines a path to all of the pages on your site. Keeping this page updated, clean, concise and organized can benefit a site. For example, by providing users and engines links to the 5-10 most recent news articles and archiving the rest on pages organized by year, is a way to provide links to all news articles without listing them all or just linking to an umbrella news page. Also, by updating the list of most recent articles, new and fresh content is being added to the sitemap as frequently as your company creates news articles. If you can keep your sitemap to around 100 links, you are golden. According to Google’s Webmaster Guidelines:

“Offer a site map to your users with links that point to the important parts of your site. If the site map is larger than 100 or so links, you may want to break the site map into separate pages.”

DNS / Server Setup
I definitely am not claiming to be any sort of expert on server setups, but the way a server generates URLs or as I learned earlier this week, the way a server allows subdomains with a CNAME, can greatly affect search engine positions and indexing. So be sure only one version of your site resolves and that your URLs are consistent and somewhat clean. Google’s Webmaster Guidelines urge….

“Don’t create multiple pages, subdomains, or domains with substantially duplicate content.”

“If you decide to use dynamic pages (i.e., the URL contains a “?” character), be aware that not every search engine spider crawls dynamic pages as well as static pages. It helps to keep the parameters short and the number of them few.”

CSS
We all know that the engines can’t read JavaScript, so recently, I suggested a client use a CSS dropdown in place of his current JavaScript powered menu. Because I use FireFox for a majority of my testing, when he emailed me later in the week and said he couldn’t get it to work, I was perplexed. I tested it in Internet Explorer just to see what happened and, sure enough, it didn’t work. A member of my team tested it in IE on his computer and it worked…still perplexed. We worked with the code for a bit until it dawned on us, I still have IE 6 on my computer and he has the updated, IE 7 version on his. And here lies the problem, IE 6 doesn’t support the a:hover function. Just something to keep in mind.

In closing, I would just like to mention that a quality SEO looks at much more than just title and meta tags. There are many, many reasons sites can have trouble positioning in the SERPs, and a good SEO will look into these issues and suggest quality fixes to these issues. A good SEO also focuses on usability and works with the client to improve the optimization of the site as well as the experience of the users.

GD Star Rating
loading...

Socialize This Post

If you enjoyed this post, make sure you leave a comment.