Posted by Ben C on 06/16/07 08:21
On 2007-06-16, Jon Slaughter <Jon_Slaughter@Hotmail.com> wrote:
> Say I'm giving a hypothetical structure such as(in reality it would be more
> complicated with arbitrary nestings)
>
><div id="PageComments">
> <div>
> Mike Jones - Subject
> <div>
> Jone Smoth - Subject2
> <div>
> Mike Jones - Subject2
> </div>
> </div>
> <div>
> Jeff - Subject3
> </div>
> </div>
> <div>
> Mike Applehaead - Subject is dead3
> </div>
> <div>
> Cable - Subject is dead5
> </div>
></div>
>
>
> Is there a way to apply a style recursive to it to so that each div is given
> the same style?
div { ... }
or #pageComments div { ... }
> What are the pro's and cons of inlining or using class=?
A class is usually better than using inline style attributes since all
the properties go in one selector. Whether you need a class or just a
descendent selector depends on your application.
> What I'm afraid of is that if I use some type of css recursion that it might
> slow down the browser when it is applying the styles.
Most unlikely. You have to think this through: the browser is going to
have to do something with every <div> in your page anyway to work out
where to draw it on the screen. It's the least of its worries to add a
style from a simple selector like div { ... }.
There's no reason to assume it's programmed like this:
for each div
apply styles
for each div
do everything else
rather than like this:
for each div
apply styles
do everything else
and in any case there's not much reason why the former should be
significantly slower.
In fact using a selector rather than inline styles may be a tiny bit
faster because of the reduced amount of parsing.
A more complex selector like div td div { ... } will be slightly harder
to match since it's a little bit like an easy version of matching a
regular expression, but I wouldn't worry about it.
Navigation:
[Reply to this message]
|