Groups | Blog | Home
all groups > asp.net webcontrols > june 2004 >

asp.net webcontrols : Applying styles from multiple sources



DalePres
6/26/2004 8:32:14 AM
Is there a way to determine the order or priority of applying styles in a
custom web control? For example, I have a control with default style
settings for many features, and exposed public properties to change those
settings as well. It is easy enough to set the value of the public property
to the default, then use the public property to render my control.

Where it becomes more confusing is when applying style sheets. If a
developer uses my control and applies a style sheet, I have no way of
knowing which style parameters he has applied in the style sheet. Therefore
I don't know which default styles to leave out of my rendering.

So the bottom line is, I think, how to prioritize and apply styles from
default styles, public property styles, and css class styles.

Thanks,

Dale

Dale
6/28/2004 9:15:11 PM
Second try here... Microsoft, Where're those 48 hour responses advertised in
my MSDN subscription?

Is there a way to determine the order or priority of applying styles in a
custom web control? For example, I have a control with default style
settings for many features, and exposed public properties to change those
settings as well. It is easy enough to set the value of the public property
to the default, then use the public property to render my control.

Where it becomes more confusing is when applying style sheets. If a
developer uses my control and applies a style sheet, I have no way of
knowing which style parameters he has applied in the style sheet. Therefore
I don't know which default styles to leave out of my rendering.

So the bottom line is, I think, how to prioritize and apply styles from
default styles, public property styles, and css class styles.

Thanks,

Dale


Iain
6/29/2004 9:12:55 AM

[quoted text, click to view]

(I'm not microsoft, and am asking questions too - so don't expect too
much!).

Dale - I rather think that what happens will happen exactly as if all the
style elements had been included in the resulting html. In fact that may be
exactly how it works. Of course the style parse may well ignore overriden
elements, but it won't know which they are for elements in style sheets
defined outside .net.

So in short I wouldn't worry about it. Any specific style="" in an element
should override higher elements.

Accordingly you should look at the style prioritisation rules.

There's a little bit on this in 'Dynamic HTML' by Danny GOodman and no doubt
an incomprehensible standard at W3C somewhere.


Iain

Scott G.
6/29/2004 9:40:55 AM
I've dropped one of the groups from your xpost.

In general what I do is whenever someone sets the CssClass property of =
my control I drop all of the internally generated styling; =
unfortunately, a lot of this is browser dependent -- but in general, the =
style=3D attribute is the bottom of the cascade, and thus will override =
everything before it (modulo any browser bugs). There are some tricky =
bits here, since some of the CSS qualifiers can set several things at =
once, for example, one could have :

..tag { font: italic small-caps bold 12px arial; }

And in your HTML:

<foo class=3D"tag" style=3D"font-family: verdana;" >....

In this case we should have overridden the "arial"; but in practice that =
doesn't always work.

Anyway, because of these kinds of things, I do what I suggested above, =
which is to not generate a style=3D if the user sets the CssClass=20

An alternative might be to never assume any defaults for styling and =
then if the user of the control sets something, then it's set. Or since =
you have control of the control you are writing, you could add a =
property that says/does something like "NoStyleAttribute".

Scott
[quoted text, click to view]
Second try here... Microsoft, Where're those 48 hour responses =
advertised in
my MSDN subscription?

Is there a way to determine the order or priority of applying styles =
in a
custom web control? For example, I have a control with default style
settings for many features, and exposed public properties to change =
those
settings as well. It is easy enough to set the value of the public =
property
to the default, then use the public property to render my control.

Where it becomes more confusing is when applying style sheets. If a
developer uses my control and applies a style sheet, I have no way of
knowing which style parameters he has applied in the style sheet. =
Therefore
I don't know which default styles to leave out of my rendering.

So the bottom line is, I think, how to prioritize and apply styles =
from
default styles, public property styles, and css class styles.

Thanks,

q NO[at]SPAM q.com
6/30/2004 7:16:12 AM
Styles trickle down.

or
think bottom-up.

an embedded style overrides an inline style,
which in turn overrides linked stylesheets.

hope this helps

[quoted text, click to view]
DalePres
7/1/2004 8:21:20 PM
Thanks all for your advice on this one.

Dale

[quoted text, click to view]

AddThis Social Bookmark Button