Reputation: 43768
Does anyone know how can I detect the browser type in css? What I trying to do is when the user viewing the page by using IE 8, then will set class 'black2' to { font-size:0.75em; color:#1e549b;} in css else will set it to { font-size:0.95em; color:#1e549b;}
Upvotes: 0
Views: 6438
Reputation: 31781
I am mentioning this for the sake of completeness, but I strongly advise that you go a different route because CSS expressions impact performance and may not be cross-platform-friendly:
You can use a CSS expression coupled with JavaScript to dynamically set your styles. An example:
<style>
P
{
background-color: expression( getBackgroundColor(this) );
}
</style>
<script type="text/javascript">
function getBackgroundColor(elem)
{
return "green";
}
</script>
You can use this JavaScript function to sniff out the browser version (also not the best idea) and color accordingly.
Upvotes: 0
Reputation: 607
If you are running server-side code (php, asp.net, asp, ..), you would be better off detecting the browser on the server and including an additional style sheet in the header for browser specific code.
Otherwise, the are a number of browser hacks you could use to inject CSS for different browser types and version. As they are "hacks", the css gets ugly fast.
Upvotes: 0
Reputation: 186562
<!--[if IE 8]>
<style>.black2 { font-size:0.75em; color:#1e549b;} </style>
<![endif]-->
Not really recommended...but why are you serving a different font size? You can't get them to be consistent? Have you tried setting an initial percent, then use ems?
Upvotes: 2