How to document CSS for a large site [closed] - html

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
We maintain a fairly large site with a lot pages. As the pages grew, so did the HTML and CSS. Is there any good way to document these? Like which page uses a particular selector, etc. What's the best practice for maintaining CSS for a large site?

In my experience, CSS is not maintainable. If CSS were a room in your house, it's the basement...it collects things over the years and after a while you tend to have more stuff in it that is of no use vs. stuff you want to keep.
As such, I recommend starting fresh every few years.
Barring that, some suggestions:
Maintain the CSS dev-side in as many separate files as it makes sense to have. Use a minimizer to compress and combine it all into one file for deployment.
look into OOCSS (Object Oriented CSS) methods. I try to use that these days for sites that have large teams of developers. The basic concept is to have more class names in your HTML, but what class names you have are much more re-usable across the entire site, so your CSS files should remain more streamlined.
build component libraries. A major goal is to NOT have specific css for each individual page. Instead, leverage reusable code and design patterns across the site.

We use rails and follow this architecture: http://codefastdieyoung.com/2011/03/css-js-organization-best-practice/
Depending on the framework you use, you might have to tweak the logic accordingly.
Brief explanation of the architecture:
In rails there is a way to specify a common ID for a group of pages.
For ex: all the pages related to users management can have this id: body#users-registration.
Similarly all the pages related to reporting services ca have this id: body#reporting-services
Having said that, have a common.css file which contains generic styles that are reusable across the site - like layout styles, li, p, panels, etc.
And then have separate css files for each & every group of pages: users-registration.css, reporting-services.css. These files will have the styles that are specific to the corresponding group.
In this way we have managed to avoid conflicts across the pages as well.
Note that we finally combine all the CSS files into a single css file and render that in production.

I've found that commenting my CSS and targeting HTML tags vs "class1, myselector27, etc" has made for a lot less code, and simpler to read later on. If I have a JavaScript event that needs to be isolated, I wrap that component in an id and comment the base CSS file accordingly.
reset.css
fonts.css
main.css
main.css
/*
** Image Slider for products.php
*/
#slider_products {...}
#slider_products #slide_container {...}
#slider_products h1, p {...}
#slider_products img {...}
If you are using an IDE (like NetBeans) these comments can be made visible (and you can also write as much descriptive text as necessary, if need be)
I've maintained CSS files for sites with over 200 pages of content, and those with 20 pages. In either case, my CSS files have never been in the 1200-lines-of-code-range, which I've seen in a friend's portfolio site (no names :-)), but his site is #best 20-30 pages - ALL of which share the same design, style, look - it's OVERKILL. One has to believe that if the CSS and code were to be combed-through those 1200 lines could be reduced substantially pretty quick.

There are a few things you can do.
Place your the CSS in your stylesheet in order of the page. So, header styles at the top, then main content styles, then footer styles. Below that, you can add additional styles for certain uses.
Use comments in your styles, e.g. /* ### Styles for Links in Main Content #### */
Use separate stylesheets for separate sections, if the CSS is large enough. So, if you have a section of the site that deals with a specific topic and it has significant style modifications, give it its own stylesheet and only reference it in that section.
Use the cascade wisely and cut down on the amount of css you write. A simple example here: http://csswizardry.com/toybox/use-the-cascade/

I've seen a few systems that delineate between CSS written for the interface, with reusable class names as DA points out, but they did go ahead and give an architectural breakdown of these classes, since their intention is to be reusable. Then they went on to use verbose selector names for components and granular features - which generally weren't documented, and were provided by 3rd parties mainly.
It worked fairly well, and I imagine if the interface were redesigned at some point it would be an arduous but doable job to re-work the interface CSS and documentation, while leaving the component styling down to the 3rd-party providers/developers, or whoever creates the components.
As the others have said, don't let CSS documentation lure you into avoiding minification, even if it isn't automated, but beware, if your CSS is sprawling and unaccountable when you minify, you may find your resulting styles aren't quite on par - depending on the minify settings used.
EDIT:
Hot off the Google+ feed - Jonathan Snook is writing up something related to this thread, here's the temporary link to keep an eye on: http://smacss.com/

Related

How can I edit codes like social media link or remove something from all of my web pages in notepad++ automatically? [duplicate]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed last year.
Improve this question
It seems like I'm a bit outdated on website creation.
Some years ago I learned to create simple websites with frames.
Yet this solution is discouraged by w3school.com and frames are no longer supported in future HTML versions.
So what are the simple replacements?
iFrames also seem to be discouraged by most developers
PHP seems to provide a solution? what is a simple way in php to replace frames?
if I'm not using php (actually I need to use JavaEE in one project), how can I create frame-like websites?
Short: How to create a good-looking (frame-like) website nowadays?
Generally speaking:
Visually
CSS. There are numerous techniques for laying content out (depending on the precise effect you want, Holy Grail is a common desire).
The overflow properties handle scrolling sub-sections of pages, although designers who think that having a menu using up screen space all the time is a good idea are usually wrong.
Avoiding duplication of metacontent
(i.e. putting things like basic structure, navigation menus, etc on every page without copy/pasting them)
A template system (or an include system) that either runs server side (most common) or at build time (which can support HTTP servers which only allow static files).
The language this is implemented in is irrelevant, PHP is as common as muck, Java is an option, I tend towards Perl (and more specifically: Template Toolkit), there are many others. JavaScript is becoming increasingly popular for this type of job, with tools such as assemble becoming available. You can go all the way with a static site generator.
Use a search engine to find popular template languages or include systems for your programming language of choice.
Loading new content without leaving the page
JavaScript, usually with the XMLHttpRequest object (the technique being known as Ajax), and (if you are doing serious content changes) used in combination with the History API (so bookmarking and linking still works). Github are a good example of this. There are various frameworks such as React and Angular which try to make things easier. Note limited browser support and all the other things that can cause JS to file makes using good design principles essential. One approach to making these things robust is to write Isomorphic JS.
Frames are not replaced by a new "technology". The state of the art is to put all content into the same document and style it via CSS. Of course server side includes can help you to do this.
Use CSS positioning to create a frame-like interface and AJAX to change the content of a container. You can use JavaScript frameworks like jQuery, Prototype or MooTools to handle AJAX requests.
However, if you want to include content from another domain you have to use an <iframe>, since AJAX follows a same origin policy.
If you want to write DRY (don't repeat yourself) you could use some kind of template system (PHP, Ruby, Pearl, Python - and of course a framework for this languages).

single HTML file for navigation bar in every file [duplicate]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed last year.
Improve this question
It seems like I'm a bit outdated on website creation.
Some years ago I learned to create simple websites with frames.
Yet this solution is discouraged by w3school.com and frames are no longer supported in future HTML versions.
So what are the simple replacements?
iFrames also seem to be discouraged by most developers
PHP seems to provide a solution? what is a simple way in php to replace frames?
if I'm not using php (actually I need to use JavaEE in one project), how can I create frame-like websites?
Short: How to create a good-looking (frame-like) website nowadays?
Generally speaking:
Visually
CSS. There are numerous techniques for laying content out (depending on the precise effect you want, Holy Grail is a common desire).
The overflow properties handle scrolling sub-sections of pages, although designers who think that having a menu using up screen space all the time is a good idea are usually wrong.
Avoiding duplication of metacontent
(i.e. putting things like basic structure, navigation menus, etc on every page without copy/pasting them)
A template system (or an include system) that either runs server side (most common) or at build time (which can support HTTP servers which only allow static files).
The language this is implemented in is irrelevant, PHP is as common as muck, Java is an option, I tend towards Perl (and more specifically: Template Toolkit), there are many others. JavaScript is becoming increasingly popular for this type of job, with tools such as assemble becoming available. You can go all the way with a static site generator.
Use a search engine to find popular template languages or include systems for your programming language of choice.
Loading new content without leaving the page
JavaScript, usually with the XMLHttpRequest object (the technique being known as Ajax), and (if you are doing serious content changes) used in combination with the History API (so bookmarking and linking still works). Github are a good example of this. There are various frameworks such as React and Angular which try to make things easier. Note limited browser support and all the other things that can cause JS to file makes using good design principles essential. One approach to making these things robust is to write Isomorphic JS.
Frames are not replaced by a new "technology". The state of the art is to put all content into the same document and style it via CSS. Of course server side includes can help you to do this.
Use CSS positioning to create a frame-like interface and AJAX to change the content of a container. You can use JavaScript frameworks like jQuery, Prototype or MooTools to handle AJAX requests.
However, if you want to include content from another domain you have to use an <iframe>, since AJAX follows a same origin policy.
If you want to write DRY (don't repeat yourself) you could use some kind of template system (PHP, Ruby, Pearl, Python - and of course a framework for this languages).

Are separate css files always considered superior to inline styling? Even for one-off adjustments? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have a fairly big single page application I'm working on. I can put the styles inline in the html tags, e.g. <div style="width:10px"></div>, or I can put it in a separate .css file and reference tags via classes or ids.
Obviously I'm using .css and classes/ids for styles (re)used many times. But there's a lot of one-off elements that just need a little specific adjustment here and there, e.g. a small margin to make it look just right, and creating a new class or id for each one of them seems extraordinarily cumbersome. I end up with lots of one-off classes and ids that are not easy to navigate, and instead of finding the style information where it's used (in the relevant tag), I have to go search in some random .css file.
Yet, the internet tells me it is always preferred to keep all my style information in .css files. Who's correct? Have I stumbled upon a specific case where inline styling is better, or would I somehow be shooting myself in the foot by doing that? Is there perhaps even a third way that is better?
Yet, the internet tells me it is always preferred to keep all my style information in .css files. Who's correct?
You do realise you're asking the internet here...? ;)
Having had to redo several websites where styling had been applied using inline tags, I can say without any hesitation that I would never, ever use them myself. They are a nuisance to maintain and unless you're keeping a close record of where and what you have applied the inline styles, it is difficult to ensure that your changes to global css files will be respected throughout the site.
If you do need page-specific css classes and you don't want to put them in the global css file, add them to the page head in a <style> element. Putting all your css in a single file has the advantage that the users' browsers will load the file and cache it, so that it won't need to be reloaded on other pages of the site.
If you are finding you have a lot of tweaks to make all over the place, it suggests the design may need rethinking or refactoring. This is particularly the case with margins and padding--you can make a lot of work for yourself by choosing the wrong combination to apply spacing to your document elements.
Even for the one off styles I think a nice approach would be to have a specific file used during development called oneoff.css for example where you could have your style rules for one off situations.
This makes them easy to find and you get the benefits of having external .css files (separation of concerns, reusability even if you think you will never need to reuse I bet you will, and cacheability).
You have to weigh the pros and cons in the context of your particular organization and applications. For example, standards are more important in a team environment than on an individual project or quick utility. Would inline styles on your pages be a surprise to someone making global changes?
For what it's worth, my large organization has a strict policy against inline styles, but in my opinion there's no definitive answer to your question. There's a good Stack Overflow post on this: Comparison of loading CSS inline, embedded and from external files
therefore define multiple classes and apply styles to an external file (external.css) is more orderly. however you can use online <tag style="..."></tag> or labels styles 'style'
<style>some style</style>,
will not have any problem it is important to have the code neat and tidy. that's it

single css or multiple for responsive design - css speed

They're are already plenty of questions about many css files vs one and the solution is to use one because of fewer http request. That's not what I am asking :P
I generally would use two css files. One for the entire site and one for the specific page overwrites.
My thinking behind it is that it will speed up the css since there isn't as many css selectors that need to be evaluated for every element on the page.
Requiring the client to download one more cachable css file seems like it would be worth speeding up the browsers rendering. Especially for larger sites or sites that need lots of custom css for each page.
On the other hand the page files will have additional media queries.
What do you think is the best solutions?
While a technically correct answer would require inside information on your server's performance, your visitors' behaviour and what kind of site you're designing, I'd like to explain my basic reasoning wether to use one or many CSS documents.
For any small, basic site I'll stick to one CSS document, no questions asked. However once a site becomes more complex there may be scenarios where it's reasonable to use more documents.
If a site has several pages with very different CSS and/or markup, or one-off-type pages such as a campaign landing page, or several very different types of content such as a forum or a blog or similar, then I think it makes sense to split up your stylesheets in many documents.
The structure of said stylesheets would, again, depend on the type of site you're designing. Global rules such as normalizing/resetting CSS, general structure and media queries could be in one document, while keeping page-specific rules in another.
This makes sense to me since your visitors can cache the basic structure which should be used on every page anyways, without having to download all the CSS needed for your blog or campaign page until they actually visit it.
I agree that if you have big site with different type of pages your should split your css into different files. However I think that this should not be made based on pages. It should be made on components. When you design CSS you have to split your pages into modules. A module should contain its styles and its media queries. I found that putting the media queries in different file leads to slow development. You may even end up with something like CSS constructor. I.e. a tool which selects the specific modules, combine them in a file and server it like that. You still have only one file, but its content is different.
For CSS optimization check out this tool http://bem.info/tools/csso/

why do people still use tables, inline css, et al? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
When you learn HTML and so forth nowadays, the mantra is always "Clean code = better code".
So why do sites like Mobile Me and Google and Facebook all use huge amounts of tables and other not-semantically correct code?
Thanks!
Because people still use IE6, unfortunately, and it's so incredibly bad at CSS as to make it almost worthless for CSS selectors of any sophistication. Until IE6 is gone and dead dead dead in the cold ground, you're still going to see a lot of this.
If you could see what SharePoint generates, you would probably go into seizures.
Clean code is better, yes.
But working code is much much better )
Because sometimes that's the path of least resistance. It's not always about being ideologically pure, it's about being pragmatic and getting the job done in this crazy, multi-browser, multi-platform world.
Because it's easier.
While the purist in me will also strive for semantic tags and external CSS for layout, the pragmatist in me need to get this site up by 6pm (so I can go home to my wife and a nice warm dinner!) and there's just this little problem with [insert browser here*] that could easily be solved with a bit of conditional CSS, or a table or something.
There are other reasons for high-traffic sites like Google and Facebook to use inline CSS and js: bandwidth. Every external file you reference is one extra round-trip to the server to fetch. Of course, that doesn't really explain the style="xxx" tags as opposed to just inline <style> tags, but it still reduces the size of the page. Also, while caching does tend to reduce the number of trips, there are still a significant number of requests that are made with a "clean" cache that you still want to optimise for that case.
Not always IE (but mostly is)
I had an affiliate marketing client the other day who wanted me to make him a web template where he could go in and edit it with Adobe Dreamweaver (some app I don't use because I'm a Linux user). So, being the web-savvy guy I am, I did it in XHTML with cross-platform CSS that I have learned over the years, using DIVs primarily, and only using TABLES for form field alignment simply because of the 80/20 rule. It was lean code in as few lines as possible, loaded super fast, and worked on all browsers from IE6 on up.
But then I handed it off to him, and he was visibly frustrated and asked me to make changes. He didn't like the CSS because he couldn't cut and paste sections to another page and have the styling carry over. Instead, he wanted me to switch everything to inline styles. Next, he couldn't edit the floating DIVs very well, and would undo my cross-platform work I had done, so he wanted it reverted back to tables. The end result was XHTML + CSS for the shell of the page that centers everything into the middle and adds the fancy graphics around the page. Then, I used PHP "include" separation for headers and footers. The final part was the middle of the page, and that was his domain. I had to compose it in TABLEs with inline styles. At that point, he was happy and I had a compromise.
So, keep this in mind that there are some cases where you have to use TABLE formatting and inline styles because that's all the client really knows how to manipulate.