Anyone dynamically generating CSS based on browser-type out there? I''ve currently hacked my application in the most disgusting of ways to pull off what I need to support my project - but I''m just not pleased with the implementation. That said - it would seem a very poor idea to actually dynamically generate CSS - probably best to create static files per browser (let''s say two if you needed to support two browsers) and return the appropriate css based on user agent? Would it be possible to put this behind an action that read something like.. def get_style if request.user_agent.includes("some_cryptic_ie_string") render :template => "path/to/css" end end Any assistance? TIA! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Cory, I would put the style name to an instance variable. def define_style if request.user_agent.includes("some_cryptic_ie_string") @style = "style1" else @style = "style2" end end In your view (most likely in your layout), add following line. You need to put style1.css and style2.css in public/css. <%= stylesheet_link_tag @style %> Also, do not forget to add before filter. class YourController < ApplicationController before_filter :define_style This way, define_style is called every time the controller is processed. Cheers, Glen On Oct 9, 1:31 pm, Cory Wilkerson <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Anyone dynamically generating CSS based on browser-type out there? I''ve > currently hacked my application in the most disgusting of ways to pull > off what I need to support my project - but I''m just not pleased with > the implementation. > > That said - it would seem a very poor idea to actually dynamically > generate CSS - probably best to create static files per browser (let''s > say two if you needed to support two browsers) and return the > appropriate css based on user agent? > > Would it be possible to put this behind an action that read something > like.. > > def get_style > if request.user_agent.includes("some_cryptic_ie_string") > render :template => "path/to/css" > end > end > > Any assistance? TIA! > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Cory Wilkerson wrote:> Anyone dynamically generating CSS based on browser-type out there? I''veHow would you know the browser type? The request-header? Javascript? How about these tricks: ------------------------------------------------------------------ How to target IE6 with a CSS rule ------------------------------------------------------------------ Prepend the property name with an underscore. Example div.red { _margin-left: 50px; } Then a <div class="red"> will have margin-left: 50px applied but only in IE6. ------------------------------------------------------------------ How to target IE7 with a CSS rule ------------------------------------------------------------------ 1. Add a class to the body element. It can be chosen arbitrarily; it is only important that the body-element has a class: <body class="some_name"> 2. Add rules like this. body[className] div.red { margin-left: 50px } Then a <div class="red"> will have margin-left: 50px applied but only in IE7. Reference: http://pnomolos.com/article/6/a-valid-css-hack-to-target-only-ie7 Stephan -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If it''s mostly IE you''re having problems with, have a look at IE''s ''conditional comments''. You can specify code you only want to be visible to IE, or specific versions of IE. This means you can write your CSS for the more standards compliant browsers, and include IE hacks in one file like so: <head> <!--[if IE]> <link rel="stylesheet" type="text/css" href="ie-hacks.css" /> <![endif]--> </head> See http://www.quirksmode.org/css/condcom.html Joel. On Oct 10, 9:31 am, Cory Wilkerson <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Anyone dynamically generating CSS based on browser-type out there? I''ve > currently hacked my application in the most disgusting of ways to pull > off what I need to support my project - but I''m just not pleased with > the implementation. > > That said - it would seem a very poor idea to actually dynamically > generate CSS - probably best to create static files per browser (let''s > say two if you needed to support two browsers) and return the > appropriate css based on user agent? > > Would it be possible to put this behind an action that read something > like.. > > def get_style > if request.user_agent.includes("some_cryptic_ie_string") > render :template => "path/to/css" > end > end > > Any assistance? TIA! > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> <head> > <!--[if IE]> > <link rel="stylesheet" type="text/css" href="ie-hacks.css" /> > <![endif]--> > </head>was just going to post the above :) ... passed just around the corner! you can do this as well: <!--[if lt IE 7]> <link rel="stylesheet" type="text/css" href="specialie.css" /> <![endif]--> the lt (<) / gt(>) operators on IE 7 IE 6 -> for any browser that is less than / greater than IE 6 / IE & etc ) i would stick to css hacks and if IE comments rather than mix this heavily into the app, but whatever suits u :p enjoy -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Not exactly what you asked but I thought I''d mention, I use this for dynamic css and love it. http://www.misuse.org/science/2006/09/26/dynamic-css-in-ruby-on-rails?story=20060926084103529 Basically you create a controller (rcss_controller) and your css file(s) are just templates which can now contain ruby code, instance variables, etc. linoj On Oct 9, 7:31 pm, Cory Wilkerson <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Anyone dynamically generating CSS based on browser-type out there? I''ve > currently hacked my application in the most disgusting of ways to pull > off what I need to support my project - but I''m just not pleased with > the implementation. > > That said - it would seem a very poor idea to actually dynamically > generate CSS - probably best to create static files per browser (let''s > say two if you needed to support two browsers) and return the > appropriate css based on user agent? > > Would it be possible to put this behind an action that read something > like.. > > def get_style > if request.user_agent.includes("some_cryptic_ie_string") > render :template => "path/to/css" > end > end > > Any assistance? TIA! > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks all! Conditional comments it is! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Another good reason to use conditional comments is that you aren''t preventing yourself from ever being able to use page caching... Then the html output is the same regardless of the UA. Of course this doesn''t matter if your pages are all user-specific anyway, but some of the cms stuff I''ve built does very well with page caching since everyone sees the same page. Matt On 10/10/07, Cory Wilkerson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Thanks all! Conditional comments it is! > -- > Posted via http://www.ruby-forum.com/. > > > >-- Matt White ----------------------- Thermal Creative http://blog.thermalcreative.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---