JackMahoney
JackMahoney

Reputation: 3433

CSS white or transparent background-color for div on white background?

I work in front end and set CSS background using the shorthand notation very often. I was wondering for a div with a background image whose parent div has a white background - should the child have background-color white or transparent ? Which is better for performance?

ie:

<div id='parent' style='background:white;'>
    <div id='child' style='background:WHITE image no-repeat center center;'></div>
</div>

OR

<div id='parent' style='background:white;'>
    <div id='child' style='background:TRANSPARENT image no-repeat center center;'></div>
</div>

Upvotes: 2

Views: 16404

Answers (2)

Shawn Wernig
Shawn Wernig

Reputation: 1742

Everyone's right suggesting that you leave off the declaration. It's good cascading.

However, you may want to declare it white when the interior element requires a white background - In which case it would be sensible to include it in the event this element will appear in other places.

The performance gains either way are largely unnoticeable I would say.

Upvotes: 1

GitaarLAB
GitaarLAB

Reputation: 14645

Simply don't set the background color in the shorthand declaration. You can skip it.
Saves on bandwidth, and css-browser-rendering-performance is kind of totally Dependant on the users/visitors browser!

Good luck!

Upvotes: 1

Related Questions