PDA

View Full Version : CSS Layout Questions


lisa315733
04-17-2009, 04:13 AM
Although I have been designing sites for several years using table-based layout, I am new to CSS Layouts and that is why I purchase CSS Sculptor and am trying to understand the proper way of using CSS to layout a site and have a few questions as to how/why CSS Sculptor formats the CSS the way it does.

An example would be:

#outerWrapper #mainContentWrapper #insideContentWrapper #content #equipment a:link, a:visited

1) I could understand this if every div needs the properties of #outerWrapper but if they don't then shouldn't it be formatted like this instead?

#outerWrapper {
formatting }
#mainContentWrapper {
formatting }
#insideContentWrapper {
formatting }
#content {
formatting }
#equipment a:link, a:visited {
formatting }


2) Also, I have seen on several sites where the CSS div is formated differently and am trying to understand the use or do they all do the same thing?

#wrapper
div#wrapper
d.wrapper


3) Using Resets. I understand the concept of using resets at the top of a css file in case a tag isn't closed but what is the proper formatting?

Is this how a CSS file should be formatted:

Resets (i.e., HTML, Body, p)
Layout DIVs (i.e., #wrapper, #contentWrapper, #leftColumn, #content)
Classes (i.e., img border, etc.)

So should the classes be located at bottom of the CSS file, unless they are specific to a DIV?

I have noticed this because I am continuously running into problems with styling links differently depending on which section I'm on. Many times the previous link style gets overwritten by the one that comes after it so I am trying to understand how this works. For example, if I define my site wide links at the top of the CSS and then get more specific and do #content a:link, #leftColumn a:link, #content a:link, and have these all different, shouldn't each div link be styled differently?


Thanks,
Lisa

Justin Nemeth
04-17-2009, 10:03 AM
Hi Lisa,

1)
That code limits to the scope of the css. What I mean is code like "#outerWrapper #contentWrapper" corresponds to HTML like "<div id="outerWrapper"><div id="contentWrapper"></div></div>". Notice how the #contentWrapper is nested inside the #outerWrapper div. If the #contentWrapper was somewhere outside of the #outerWrapper, the css would not be applied. It justs a way of setting the scope of your css and should help with possible cascading issues if you are too general with the css declarations.

2)
#wrapper - will style any element with an id of wrapper
div#wrapper - will only style a div tag with an id of wrapper

If you prefix and #id or .class with a HTML tag name, it just limits what the css can be applied to. In general, being this specific is not a requirement, but it might make your css easier to read in some cases. For example, if you have css like "input.phoneNumber", that would cleary indicate you were styling an input format element.

3)
The reset css at the top of the css code is to help level the field between the various browsers. It helps each browser be more consistent in how it renders things since we are essentially telling it what to use as a baseline.

CSS is read top down and things will cascade down like you mentioned. So say at the top of the css you have a very general declaration like "a { color: red;" and later on you have "a.customLink { font-weight: bold; }", your a.customLink will also be read since the css would cascade down.

--

Let me know if you have any other questions.

lisa315733
04-18-2009, 04:47 AM
Justin,

Thanks so much for the explainations. They have help considerably and have put me on the right path of understanding CSS... one more baby step.

Lisa