Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am a regular user of Wordpress and whenever I feel the need to change the look of a DOM element, I prefer to use it inline. This is just because I don't want go back to the stylesheet and create new classes and styles for a single different looking element on a particular post. Can anyone please list the PROS and CONS of this technique. And should I change it?

PS - All suggestions should be given keeping the CMS factor in mind.

share

migration rejected from stackoverflow.com Jul 22 at 3:36

This question came from our site for professional and enthusiast programmers. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

closed as too broad by MichaelT, GlenH7, DougM, gnat, Robert Harvey Jul 22 at 3:36

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
I like this question but think it should be on Programmers.SE –  Fosco Jun 1 '11 at 3:48
    
Can you please specify the reason why? –  PsyCoder Jun 1 '11 at 3:49
    
Your title suggests you want to store your CSS in a CMS, but your question doesn't really explain that clearly. Is that what you're asking? What are the pros and cons of storing your CSS rules in a CMS? –  John Weldon Jun 1 '11 at 3:49
3  
It is a subjective question about programming style, rather than a problem looking for a solution. –  Fosco Jun 1 '11 at 3:50
    
@john - i just want to know whether its good to add inline css in a cms like wordpress or not –  PsyCoder Jun 1 '11 at 3:50

2 Answers 2

up vote 7 down vote accepted

Pros of inline styles

  • It's quick and dirty (and we are a lazy bunch)
  • It has the same end effect as stylesheets

Cons of inline styles

  • It mixes presentational code with markup (no separation of concerns)
  • For the above reason it is harder to maintain and reduces readability of the markup
  • Can't use psuedo classes such as :hover, :focus etc., can't select multiple elements (such as all anchors in a list item)
  • No reuse of styles (which is very easy with stylesheets)

In short, I'd advise against it for 99% of the cases. Yes, adding a class and opening a stylesheet might take a few more seconds, but in the long run it is a much better practice.

share
    
tips: do your quick and dirty modifications in Firebug, then copy and move it to a stylesheet –  Lie Ryan Sep 7 '11 at 7:16

This can be a real trick -- designers tend to be very, very bad at creating tons of random, repeated classes to do things that end up polluting the project long-term.

Anyhow, there is a way to settle in the middle -- setup your CMS to also serve page-specific, user editable stylesheets. Keeps pollution to a minimum, keeps people out of the filesystem and avoids weird dependencies -- like the designer we had who was hacking in custom stylesheets he was hosting on some $1.99/month webhost.

share

Not the answer you're looking for? Browse other questions tagged or ask your own question.