Page 1 of 1

CSS or style?

Posted: Fri Apr 13, 2012 8:41 am
by IGGt
I'm just wondering abouth the following quandry:

At present I have a table that looks similar to this -

Code: Select all

<tr>
<td style="background-color: #D9FFB3; color: #000000;" class="RoundBottomLeft">7</td>
<td style="background-color: #D9FFB3; color: #000000;">88</td>
<td style="background-color: #D9FFB3; color: #000000;">27</td>
<td style="background-color: #D9FFB3; color: #000000;">36</td>
<td style="background-color: #D9FFB3; color: #000000;" class="RoundBottomRight">240</td> 
</tr>

The CSS is -

Code: Select all

.RoundBottomLeft
{
  border-bottom-left-radius: 20px;
}

.RoundBottomRight
{
  border-bottom-right-radius: 20px;
}

The table is created using PHP, based on a MySQL query. The background-color could be one of 4 different colours, depending on the result.


I have started looking at using classes to control all the style elements, as I figure it is probably easier to manage long term, and if I need to use Javascript to change any of them it is probably easier to change a whole class, rather than numerous individual style elements.


However, in my example above, I would need 12 separate classes:
RoundBottomLeft * 4 colors
standard * 4 colors
RoundBottomRight * 4 colors


Whereas in my existing setup I need 2 x classes (RoundBottomLeft, RoundBottomRight) and the default (td), and 4 x (color) styles. (7 in total).


So I was wondering what is generally considered as best practice in this example (lots of easy to manage CSS, or a smaller number, or more difficult to manage styles).

Re: CSS or style?

Posted: Fri Apr 13, 2012 8:47 am
by Celauran
You know you can apply more than one class to an element, right?

Re: CSS or style?

Posted: Fri Apr 13, 2012 8:50 am
by IGGt
From what I was reading, I was told it (multiple classes) wasn't guaranteed to be compatible with all browsers.

Re: CSS or style?

Posted: Thu May 10, 2012 1:19 am
by stelar
I am little weak in CSS but i am confident here i will get best guidance....:)

Re: CSS or style?

Posted: Thu May 10, 2012 9:43 am
by pickle
IGGt wrote:From what I was reading, I was told it (multiple classes) wasn't guaranteed to be compatible with all browsers.
That was totally untrue. You only need 6 classes - 4 for each colour, and your two rounding classes.

Re: CSS or style?

Posted: Thu May 10, 2012 10:50 am
by x_mutatis_mutandis_x
IGGt wrote:From what I was reading, I was told it (multiple classes) wasn't guaranteed to be compatible with all browsers.
If that was the case, you will not be able to use your own css in conjunction with a 3rd party css library (like jqueryui) without hacking into their code. You can assign multiple classes to an element like this: [syntax]<element class="class1 class2 class3 class4">..</element>[/syntax]