I ran across this article while trying to target specific browsers
without using conditional comments. Thought I would post to
see how others have addressed this, and perhaps as a reason to
support JQuery in Hobo. This specific solution is based on using
ASP.NET, but author suggests same solution could be done using
JQuery.


/*********************************************************/

In the ASP.NET world, I've tended to use the built-in BrowserCaps
feature to write out a set of classes onto the body tag that enable
you to target any combination of browser and platform.

So in pre-render, I would run something like this code (assuming you
give your tag an ID and make it runat the server):

HtmlGenericControl _body = (HtmlGenericControl)this.FindControl
("pageBody");
_body.Attributes.Add("class", Request.Browser.Platform + " " +
Request.Browser.Browser + Request.Browser.MajorVersion);

This code enables you to then target a specific browser in your CSS
like this:

.IE8 #nav ul li { .... }
.IE7 #nav ul li { .... }
.MacPPC.Firefox #nav ul li { .... }

We create a sub-class of System.Web.UI.MasterPage and make sure all of
our master pages inherit from our specialised MasterPage so that every
page gets these classes added on for free.

If you're not in an ASP.NET environment, you could use jQuery which
has a browser plugin that dynamically adds similar class names on page-
load.

This method has the benefit of removing conditional comments from your
markup, and also of keeping both your main styles and your browser-
specific styles in roughly the same place in your CSS files. It also
means your CSS is more future-proof (since it doesn't rely on bugs
that may be fixed) and helps your CSS code make much more sense since
you only have to see

.IE8 #container { .... }

Instead of

* html #container { .... }

       ---jsidnell  http://stackoverflow.com/users/96518/jsidnell

/************************************************************/

Cheers,

   Jet

--

You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.


Reply via email to