encapsulation

For general web development questions that are not specifically related to CSS HTML Validator. This includes (but is not limited to) general HTML, CSS, Accessibility, JavaScript, and SEO questions.
Post Reply
User avatar
roedygr
Rank V - Professional
Posts: 367
Joined: Fri Feb 17, 2006 5:22 am
Location: Victoria BC Canada
Contact:

encapsulation

Post by roedygr »

My style sheets are bloated mainly because so many styles are identical except for one attribute.

Is there a way of encapsulating the commonality?
User avatar
Albert Wiersch
Site Admin
Posts: 3783
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: encapsulation

Post by Albert Wiersch »

Do you mean an automated way? If so then I am not aware of one but there could be something out there (though I suspect something like this would be very difficult to do automatically without unexpected side effects and other issues).

Otherwise you may have to manually re-design your styles so that they make better use inheritance in order to eliminate or reduce the unnecessary duplicate style properties.

Putting common properties in a separate class might help as well. You could then assign HTML elements that common class plus other classes... but making use of inheritance (if you can) and good design (good CSS classes, etc.) would be the best option.
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial
User avatar
roedygr
Rank V - Professional
Posts: 367
Joined: Fri Feb 17, 2006 5:22 am
Location: Victoria BC Canada
Contact:

Re: encapsulation

Post by roedygr »

What do you mean by "the cascade"?
User avatar
Albert Wiersch
Site Admin
Posts: 3783
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: encapsulation

Post by Albert Wiersch »

Hello,

This explains it well:
https://developer.mozilla.org/en-US/doc ... nheritance

Though it seems I meant to say inheritance (and will update my post). You can use inheritance to limit the amount of properties you set and simplify your CSS.
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial
User avatar
RSteinwand
Rank VI - Professional
Posts: 596
Joined: Mon Jun 09, 2008 2:12 pm
Location: Fargo, ND
Contact:

Re: encapsulation

Post by RSteinwand »

Rick
Post Reply