CSS For Web Projects - How do YOU Do it?
What do you do for your CSS? Do you use a framework like Blueprint or YUI Grids? Do you start off with a reset CSS to get a jump start? Do you break down your css into separate files (for editing)? Do you have an automated task for merging them (to minimize http hits in production)? I have some thoughts, but I'd love to get your input on what you do and why . . .
We're tempted to avoid the frameworks as I don't like the idea of having id="col_21_row_417" all over the place. I want to build a page using div id's that are focused on the meaning of the content - not it's location (e.g. primary-navigation - not top-navigation and CERTAINLY not col_1_row_3).
We are looking seriously at resets (like Meyers reset reloaded or the YUI reset - any recommendations on a good one?) to simplify some of the usual cross browser issues.
We're also looking at having a number of separate CSS files - at least one for the styles for the primary content area (to be used in our cms WYSIWYG editor styles drop down), one for the site structure and another for one off styles like a "buy now" button style (thanks Ben!).
So, what do you do, what do you think?
Also, what are people using these days for their form styles?



Generally I use several different cascading style sheets, one for the structure of the page, one for forms, one for strictly text and one to handle the so called one off styles.
I really like this layout system for the page structure, http://theholiergrail.com/. It handles menuing etc., and is reasonably cross browser without the hacks.
As for styling forms I use a separate css style sheet for form specific items. You may want to check this site on css and forms, http://www.smashingmagazine.com/2006/11/11/css-bas... It has some very good ideas on how to structure your forms using CSS. Another good one is http://www.456bereastreet.com/archive/200701/styli..., again its got some excellent ideas to use.
One thing about form styling is that I use <label for="id"></label> tags for each of the form elements along with specific styling of the p tag within th eform. This allows me to avoid all grid references or tables when constructing forms. For instance here's what I use for the form and the p tags
form { margin: 0px ; } // so there's no large gap at the top sides or bottom of the form.
.buttonStyle {
padding:0px 0px 7px 0px;
background-color:#FFF;
background-image:url(/images/formButton.jpg);
width:106px;
height:31px;
color:#fff;
border-width:0px;
vertical-align:text-bottom;
font-weight:600;
font-size:11px;
font-family: Verdana, Tahoma, Arial, Helvetica, sans-serif, 'Trebuchet MS';
}
.cssform fieldset{
background-color:transparent;
width: 440px;
}
.cssform p{
width: 100%;
clear: left;
margin: 0;
padding: 3px 0 0 0;
padding-left: 135px; /*width of left column containing the label elements*/
font: normal bold 1em/1.3em Arial, Verdana, Helvetica, Geneva, "Trebuchet MS", Tahoma, sans-serif;
/*border-top: 1px dashed gray;
border-bottom: 1px dashed gray;
border-right:1px dashed gray;*/
height: 1%;
}
Then the label:
.cssform label{
font-weight:normal;
font-size:1em;
background-color:transparent;
color: #454545;
font-weight:bold;
float: left;
margin-left: -130px; /*width of left column*/
width: 130px; /*width of labels. Should be smaller than left column (155px) to create some right margin*/
}
and the text input:
.cssform input[type="text"]{ /*width of text boxes. IE6 does not understand this attribute*/
width: 250px;
}
then the form would look something like this:
<form name="rmiForm" method="post" action="foo.cfm" class="cssform" AUTOCOMPLETE = "off" enctype="multipart/form-data">
<fieldset><legend> <strong>Your Information</strong> </legend>
<p>
<label for="name">Name</strong></label>
<input type="text" name="name" id="name" tabindex="1" value="" />
</p>
<p><input type="submit" value="Save" class="buttonStyle" />
</form>
</fieldset>
Anyhow this produces a fairly nice looking form using semantically correct markup without hacks etc.
regards,
larry
A potential downside is that some of the features introduce invalid syntax, so the files won't validate - but valid css is emitted by the preprocessor. I call the source code ASS files ;) (asp style sheets). But I'm not concerned with my css source files validating - the preprocessor makes my code so much more organized, its well worth it. Feel free to contact me if you want to know more about the syntax I came up with, or how I implemented it.
http://www.quackfuzed.com/index.cfm/2008/6/2/UniFo...
It is a set of feature rich custom tags that help create accessible, attractive, skinnable, consistant forms in a truly rapid fashion.
Take a few seconds and peruse the demo page here:
http://www.quackfuzed.com/stuff/jquery/uni-form-cu...
I try not to build an app without them.
DW
1) Reset
2) Common set of stuff (maybe have a few of these depending on your templates)
3) Site specific one
And of course I'd be considering using jQuery and I'd roll all the CSS up using Ant when I deploy.
Now sure about the form tags - I used to be a huge user of TerraForm but I'd always run into some weird issue where I had to code around it.
I understand what your saying about having things like "column span-22 first" in your html source (although with blueprint its cleaner to assign column attributes to the class not id), but your not limited to grid based design with any of the frameworks. As well, grid based design may not be ideal for all projects anyways.
I would suggest that its worth it to spend some time with blueprint. Its a great starting point thats saved me hours-upon-hours on my projects.
You may not know me but I got bored and started doing Googleblog searches for 'CSS' when your blog came up. I'm a web designer at USNews.com and we recently consolidated all of our CSS.
At first we had CSS files for different types of content named like articles.css, blogs.css, homepage.css etc. The problem with this is I noticed we were using a lot of duplicate CSS code in different files which made it tricky to manage.
Our new method consists of creating small modules that go to different packages when published live. For example we have different structure modules like twocolumn.css and threecolumn.css that control the width and float of different columns. We also have other modules like widgets that control the styles for every right-rail widget on the site. To control which modules go with which CSS files we use an XML file that basically follows this style:
<CSS file>
<module>
<module>
so using our example from above where an article is a two column page and section pages are a three column page would look like this:
article.css
twocolumn.css
widgets.css
section.css
threecolumn.css
widgets.css
It might help to look at the real deal. Here is the final combined homepage CSS file -> http://static.usnews.com/css/homepage.css if you look at the comments you can see which modules make up each CSS file using a path like http://static.usnews.com/modules/twocolumn.css
At any rate we have a python script on the backed that reads the configuration XML file, takes the contents of all the modules in a package and combines them into the final CSS file.
Now we can have several CSS code chunks used in different CSS files but only needing to go to one place to update them. Consistency goes a long, long way when dealing with a huge site like usnews.com.
Hope this has been helpful and if you have any questions, feel free to e-mail me.
This allows me to build common files that I can use in all my projects, but still have individual styles that are unique to each site.
Care to share your ant script? I'd be interested in seeing how you do the minification (is that a word?) and combine the different files together
The frameworks likewise seem like they create much more work than they save. I haven't seen a CSS framework that impressed me in the slightest.
As for the separating the CSS into separate files: I understand the issue of the extra HTTP hits, but like with anything else, you need to weigh the additional bandwidth vs. the additional development time. I suspect that except for very large sites, the savings on the development time of having your CSS organized into separate logical files will outweigh the bandwidth savings.
Finally, not to toot my own horn ... but I wrote a post on my blog a few months ago that details how to design and layout your forms with CSS. You can check it out at http://www.robhuddleston.com/index.cfm/2008/1/18/S...