encapsulation

Discussion about CSS related issues.
Post Reply
User avatar
roedygr
Rank V - Professional
Rank V - Professional
Posts: 370
Joined: Fri Feb 17, 2006 5:22 am
Location: Victoria BC Canada
Contact:

encapsulation

Post by roedygr » Wed Jan 18, 2017 4:58 am

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
Site Admin
Posts: 3242
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: encapsulation

Post by Albert Wiersch » Wed Jan 18, 2017 8:41 am

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.
Image
Albert Wiersch

User avatar
roedygr
Rank V - Professional
Rank V - Professional
Posts: 370
Joined: Fri Feb 17, 2006 5:22 am
Location: Victoria BC Canada
Contact:

Re: encapsulation

Post by roedygr » Sat Jan 21, 2017 12:49 am

What do you mean by "the cascade"?

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3242
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: encapsulation

Post by Albert Wiersch » Sat Jan 21, 2017 8:33 am

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.
Image
Albert Wiersch

User avatar
RSteinwand
Rank VI - Professional
Rank VI - Professional
Posts: 573
Joined: Mon Jun 09, 2008 2:12 pm
Location: Fargo, ND
Contact:

Re: encapsulation

Post by RSteinwand » Wed Jan 25, 2017 10:02 am

Rick

Post Reply