views:

1201

answers:

23

What are some of the most common mistakes made by CSS-Designers?

+24  A: 

Not using a reset file.

"The goal of a reset stylesheet is to reduce browser inconsistencies in things like default line heights, margins and font sizes of headings, and so on."

- Eric Meyer, Meyerweb.com

Jonathan Sampson
Agree, resetting standard rendering should be the first step. Saves headaches later.
Grant Palin
It's a good idea, but I think it resets too many things.
staticsan
@Staticsan, modify the reset to accommodate your needs. My suggestion isn't meant to suggest only Meyer's reset. If you have a smaller, less-involved, stylesheet - use it :)
Jonathan Sampson
I prefer a "set" to a "reset". It's pointless to zero all margins and padding and then add them back again later. There aren't a huge amount of elements that *need* their margins reset (e.g. `div`, `form`, `table`). Often the defaults are fine anyway and browsers mostly adhere to the defaults at http://www.w3.org/TR/CSS2/sample.html
DisgruntledGoat
@DisgruntledGoat - Meyers' "reset" doesn't set all margins and padding to zero. You must be thinking of somebody else's reset...
Jonathan Sampson
Reset stylesheets are overrated. I'll concede they have value in projects where it's crucial to maintain absolute consistency between browsers. Having to redefine all those styles you just reset tedious and usually unnecessary. Common mistake to avoid? Hardly.
Tate Johnson
@Tate, Every project is "crucial to maintain absolute consistency between browsers" to somebody who takes their job serious. I don't get paid to do "good 'nuff" work.
Jonathan Sampson
@Jonathon: uh, yes he does - look at the page linked. It's not using the * selector, but zero margins and padding are specified for practically every elements, including html, div, span, and a ton of inline elements which never have those by default.
DisgruntledGoat
@DisgruntledGoat, I'd welcome you to actually look at the stylesheet. Not *all* elements are 0 on their padding/margins. I know this from application - I use the reset.
Jonathan Sampson
Don't be so pedantic ;) - no, it's not *every single* element, hence my qualifier "practically". Anyway my two points were that (1) it's pointless to zero *anything* then add values back a few lines later - just set an appropriate default value to start with; and (2) many of the elements simply don't need to be reset - no browser sets margins on the `div` element or removes bullet points by default.
DisgruntledGoat
If I could vote this one up more than once, I would.
Martin
@Staticsan: I agree. Does anybody know of any reset styles, that do not break the presentation of the h1+, sup, and sub elements (for example)?
lhnz
“Does anybody know of any reset styles, that do not break the presentation of the h1+, sup, and sub elements (for example)?” — It’s not exactly hard to write your own. Use Eric’s as a starting point, and amend to your needs.
Paul D. Waite
+15  A: 

Using CSS hacks instead of conditional comments when writing styles for IE.

thedz
+2  A: 

Not accounting for internet explorers broken box model in quirks mode.

Sam Saffron
Even going into quirks mode in the first place is a mistake that should be avoided.
thedz
Some times you are stuck with it when maintaining an old crap website ...
Sam Saffron
Why would you maintain such a thing?
Sneakyness
A paycheck from your employer.
voyager
+10  A: 

Misunderstanding or not even considering selector specificity.

body div a.mylinkclass { }

is more specific than

a.mylinkclass { }
Joel Potter
Sorry, but this is incorrect. Try it/read the specification. (`0, 0, 0, 3` and `0, 0, 1, 1`.)
cic
Ok, fixed now, my previous comment is outdated. :-)
cic
Yup. Thanks for pointing out my mistake.
Joel Potter
+17  A: 

Thinking that:

<div class="topMargin15"></div>

with

.topMargin15 {
    margin-top: 15px;
}

Is somehow and improvement over writing it directly into the style attribute. You are supposed to be defining what it is in the HTML, and what it looks like in the CSS.

TM
Yep, way too many times I've seen something like:.Red { colour: #ff0000; }
apathetic
Most of the time it saves bandwidth.
Andreas Bonini
i can argue by saying: .NewsItem is not good either, what if I want to reuse the "style" again, do I have to create a new one with a proper name? I am going to reuse the style that is for sure, I dont want to go back to the stylesheet and create new names every time... to me, .red is more indicative of a "style" than .newsTitle
Ayyash
@ayyash - incorrect. something like .newsTitle is way more explanatory than .red. what if you want to change the design of your site a year from now and you want all your headlines to be yellow? now you've got news titles with .red classes that are actually yellow!
Jason
@Ayyash the goal is not to reduce the number of styles defined... the goal is to make the content distinct from the presentation.
TM
It's an improvement if you happen to need that class more than once and then need to modify it with an additional property like setting the padding to 0 or something. Changing it one place sure beats hunting for it everywhere.
dhulk
using such rules as a mini css framework will save a huge time in the design phase, I think.
Sepehr Lajevardi
@dhulk in that case, you need to use better selectors, not bad class names. For example, something like `.sectionTitle, .sectionBody { margin-top: 15px; }`. This stops the duplication and also doesn't screw up your document.
TM
It's also worth nothing that inline html styles are illegal in strict HTML/XHTML
Andreas Bonini
@Koper: No it's not?
cic
+12  A: 

Failing to understand the cascade and inheritance thus ending up with a lot of repeated code.

apathetic
Case in point. Cascading and inheritance are not the same thing.
toohool
That's awesome.
slypete
A: 

Using class names that are too specific and not generic enough. Eg.

.redLeftNewsHeader

rather than

.header

What happens when you decide to restyle your site with a blue theme? What happens when you want to use the class on items that are not related to news?

Dan Diplo
Absolutely, but on some sites this is necessary. Sometimes CMS (vendors) split things into fairly small chunks and modules so that your CSS ends up looking like this.
dylanfm
Usually you can get around this by wrapping a container div around the HTML and giving that a class name and then use inheritance eg.<div class="news"> <div class="header"> content </div></div>.header { color:blue; }.news .header { color:red; }
Dan Diplo
I'd rather too specific than too generic. It's confusing when css classes act on elements that you weren't expecting them to.
lhnz
@lhnz That is down to bad practise and nothing to do with using generic names. I'd rather have a generic class called .list than one called .newslist and not be able to apply it to, say, an events list because the name is confusing. Inheritance is how you sort this out, not naming.
Dan Diplo
+1  A: 

Not compressing production code with YUI's compressor

Andreas Bonini
A: 

Try to use either margin or padding, rather than both, on an element. You can save yourself from some browser issues.

dylanfm
They have separate and distinct purposes (especially when it comes to backgrounds). You just have to be aware of how they affect the box model.
Gabriel Hurley
+24  A: 

Not realizing till a year into it (like me), that you can apply more than 1 class at a time.

.Center {text-align:center}
.Disco {background: red; text-decoration: blink;}
.Highlight { font-weight: bolder;}

    <div class="Disco Center Highlight"></div>

Is valid and it will combine them all.

JBrooks
On a related note, are you aware you can create a selector that looks for two or more classes using div.Disco.Center { }?
Joel Potter
what happens if you want to change your site design and you no longer want that element centered? now you have "disco center highlight" left aligned! hmmmm...
Jason
@Joel: I know about using two classes. I did not know about the dual selector. That's cool.
Chris Lively
now forget about dual selectors again, because there is always an Inevitable Exception among browsers
n1313
“are you aware you can create a selector that looks for two or more classes using `div.Disco.Center`” — doesn’t work in IE 6 though.
Paul D. Waite
+13  A: 

Not checking cross-browser as you develop.

It's best to catch and fix the differences before the whole site is done.

I've lost count of the "My site looks great in Firefox/IE/Safari but it's all screwed up in IE/Safari/Firefox." questions.

Emily
A: 

Using "0px" instead of "0". Now I consider myself fairly good with CSS and yet I still do it sometimes...

Example: "padding: 0px" instead of "padding: 0"

Andreas Bonini
This isn't really a "mistake" because it has no negative effects, they are both the same. But it is pointless to define units when the value is zero.
DisgruntledGoat
That's not a mistake. I often do this to differentiate between things that are in px, %, and em.
Sneakyness
@Sneakyness: but if the value is 0 then 0px=0%=0em=0en=0pc etc. How does adding px differentiate anything?
DisgruntledGoat
It wouldn't make any difference, but I think it looks neater to be explicit.
lhnz
+4  A: 

Not using CSS Sprites effectively, or even at all.

Jordan S. Jones
+6  A: 

not understanding what floats are, how to use them correctly, and how to clear them!

Jason
+1  A: 

Not setting width for floating divs.

Not cascading the styles.

The following is not good:

body {   color:"#ff0; }

h2{ color:#ff0; text-decoration:underline; }

This would be better

body {   color:"#ff0; }

h2{ text-decoration:underline; }

FF0 will automatically be applied, if not interfered in some other style definitions.

Thanashyam
But what if they exist in two separate sheets (body controlled by someone other than me) and you want to force #ff0 on the h2?
Joel Potter
In that case, we are made to force the extra style. But what I am trying to point here is - we generally tend to forget the concept of Cascading.
Thanashyam
+14  A: 

Ignorance of selectors.

For example, if you have a bunch of links in your footer that you want to style differently from normal links, don't put a class on each one, use a descendent selector.

// instead of this
.footerlink {
}

// use this
#footer a {
}

You can also group selectors with commas:

#header a, #footer a {
}

Other useful selectors include:

  • child selector: E>F
  • sibling selector: E+F
  • attribute selector: input[type="text"]
  • first child pseudo class: :first-child (incredibly useful for headings - you don't want the first heading in a div to have a top margin, but you do for subsequent headings)

Unfortunately, those latter few don't work in IE6 so use for progressive enhancement only (if you support IE6).

DisgruntledGoat
+11  A: 
  • Not understanding (or even knowing about the existence of) box model

  • Not knowing what selectors are, or how to correctly use them

  • Using words to name colors (not all browsers know all the words)

  • Using invalid styles (padding:auto for example)

  • Writing #ffffff instead of #fff. (It's 3 pairs, which can be condensed into just 3 single values)

  • Not using a # on hex colors

  • Not making sure your page won't break when used at 150%-200% zoom. Old people/Almost blind people use the internet, too.

  • Not using enough contrast or white-space

  • Not validating the markup/css

  • Make sure your page degrades nicely

  • Calling yourself a CSS designer, you aren't designing a stylesheet, you're designing a website, by implementing a stylesheet.

  • Using absolute positioning (it's going to look fucked up on somebody's computer, somewhere)

  • Not keeping the stylesheet neat and organized. Don't listen to these websites that tell you to put everything on one line, because it saves bandwidth. You should keep it the way you find it easiest to read and modify, and then compress it when you're done.

  • Not putting quotes around long font names

Forgot one, my bad

  • Caring about IE6. Every time you argue that it should be supported or that people haven't updated yet, that's their fault, maybe if everything looked fucked up they'd be more motivated to download something that wasn't a heaping PILE OF SHIT. I could write a 20 page essay on how much I hate IE6, and I'm not joking. I once wrote an ex-boss a 5 page essay on why IE is the worst browser to use. He forwarded it to all his friends, and they all use Firefox or Safari now.

(I quit after he told me he wanted his website to look like his industry's leading company's website. It was an excellent website, and even had an original music score that played when you went through the galleries. He was paying me something like $15/hr (I was in highschool) and only let me come into work 9 hours a week.)

Sneakyness
"It was an excellent website, and even had an original music score that played when you went through the galleries"Bullet point 16;> Making websites with background music:P
RJFalconer
This is full of bad advice. Using absolute positioning is fine if you know how to use it (normally within relatively positioned blocks). And your reasoning applies to every single CSS rule. #ffffff vs #fff is a style issue, nothing more (I prefer consistency with the longer style).
DisgruntledGoat
If you're a multimillion dollar corporation, you're probably paying somebody enough money to put music on your website in a way that it's going to add something of value to the website. Especially in an art-related industry. It's all part of the experience, mannnnnn.
Sneakyness
*IF YOU KNOW HOW TO USE IT*. If you know how to use it, you wouldn't be making mistakes, now would you? If you are new to css, and you don't understand box model, or how to lay things out fluidly, using absolute positioning is not a viable alternative.
Sneakyness
@Sneakyness: sure, but the mistake of not knowing how/when to use positioning is not the same as your answer, which was "it's a mistake to use absolute positioning". In other words, the common mistake should be "mis-using absolute positioning" (with examples), rather than simply "using".
DisgruntledGoat
Every time I've ever used absolute positioning, it's been as a hack to make something like JQuery play nice. So, instead of me giving examples when it's wrong to use it, I'd like to see your examples of when it's right to use it.
Sneakyness
Without going into too much detail, drop down menus. Typically you set each `li` to a relative position, then the nested `ul` to an absolute position, moving it across or down. Also vital any time you want to position an element in, say the bottom right of an element.
DisgruntledGoat
+1  A: 
  • Using units that don't work with high dpi screens
  • Not using the full width of the screen
  • Not using a print stylesheet that hides everything but the content the user wants to print
ZippyV
I wouldn't class the full width thing as a mistake. Lines of text that get really long make them difficult to read.
DisgruntledGoat
A: 
  • Trying to do anything with CSS when the browser is in quirks mode.
  • Not using Firebug's tools to see the layout of your elements and refine your CSS.
  • Making fixed-height containers and not dealing with overflow.
  • Trying to use transparent PNG-24's in IE6. (Adobe Fireworks can make transparent PNG-8's that work in IE6.)
  • Not using units at all (very bad!).
Gabriel Hurley
+6  A: 

Not using Firebug

Andy Ford
A: 

Not considering your audience.

Arve Systad
A: 

I'd have to say using float's improperly and not understanding collumns. You can mutilate that kind of stuff really easily(personal experience.) so yah...float's and clear's.

codedude
A: 

writing piss poor HTML

Andy Ford