CSS organization questions

TechBoyJK

Lifer
Oct 17, 2002
16,699
60
91
I have two questions..

1. How do you list your CSS attributes? Alphabetical order? Is there any specific order that needs to be followed? I'm just trying to make things consistent so I'm thinking about having everything alphabetically.

For instance, instead of this:

Code:
.details_right
	{ 
	display: block; 
	width: 28%; 
	float: left;
	padding:0 1.5em 1em 1em;
	}

this

Code:
.details_right
	{ 
	display: block; 
	float: left;
	padding:0 1.5em 1em 1em;
	width: 28%; 
	}


2. I was reading a CSS expert's blog and he preferred to setup a class for common attributes, and declare multiple classes in the tags.

For instance, instead of this

Code:
----------------------------
.details
	{ 
	display: block; 
	float: left;
	padding:0 1.5em 1em 1em;
	width: 28%; 
	}

----------------------------
<div class="details">

Do this


Code:
----------------------------
.block {display: block;}

.float_left {	float: left;}

.details
	{ 
	padding:0 1.5em 1em 1em;
	width: 28%; 
	}

----------------------------
<div class="details block float_left">


Thoughts?
 

Woosta

Platinum Member
Mar 23, 2008
2,978
0
71
1. Don't have presentational class names. They should be semantic. Soo, dont use "block" or "float_left".

2. display block on a floated element is useless, it's already block from being a float.

3. If you need something special, use "details-" whatever:

Code:
div.details { float: left; padding:1em; width:whatever; }
div.details-alternative { float: right; }

It makes absolutely no sense giving an element a "block" class because a div is block by nature, and the float:left makes it blocky anyway so the block serves absolutely no purpose. Using this "logic" means that you should give EVERY element a class to define its display value, which would be redundant and retarded.

4. "Is there any specific order that needs to be followed?"

No, but I try to keep it alphabetic. You can also use a script that redefines your css file post save and alphabeticizes it.

I also recommend using http://sass-lang.com/

5. I was reading a CSS expert's blog and he preferred to setup a class for common attributes, and declare multiple classes in the tags.

There are a lot of self proclaimed experts, but this style only provides you with classitus. You should just have 'details' class with generic 'details' div styling. If you need something specific for special 'details' divs, then create a secondary ruleset that overrides the former.
 
Last edited:

PhatoseAlpha

Platinum Member
Apr 10, 2005
2,131
21
81
Personally, I just add to the end of the file. If I recall correctly though, selectors of equal specificity lower in the file will override ones above it, so order can matter for function - but it's rare.


That particular experts setup seems problematic at best, and missing the purpose of having stylesheets separate from the html markup to begin with. The idea was to separate out presentation from markup. Using the miniclasses he's got though, you cannot realistically alter presentation without going into the html. At which point, why even bother with classes and separate style sheets? Might as well just use inline styles if you're set on mixing up your presentation and html like that.
 

TechBoyJK

Lifer
Oct 17, 2002
16,699
60
91
Thanks guys.

So.. Does a display attribute of 'inline' get canceled out because an object is floated? Or does it affect the float in anyway?
 

TechBoyJK

Lifer
Oct 17, 2002
16,699
60
91
anybody?

Does a display attribute of 'inline' get canceled out because an object is floated? Or does it affect the float in anyway?
 

PhatoseAlpha

Platinum Member
Apr 10, 2005
2,131
21
81
As far as I can tell, display: inline simply get ignored. Doesn't seem to make any sense on floated elements anyway,
 

Woosta

Platinum Member
Mar 23, 2008
2,978
0
71
display:inline on a floated element is only useful in the case of the double margin bug in IE. I tack it on because I've been dealing with IE6 for years. If you don't care about IE6 don't bother, as 'inline' won't affect it per the spec.
 

the182guy

Member
Sep 28, 2011
27
0
0
display:inline will not affect a floated element. Have a look at the newer display:inline-block usage which can be useful.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |