7

I am wondering if there is any thing which works like ie conditional comment for webkit.

I want to change width.

For example,

<!--[if IE]>
<link href="css/ie.css" rel="stylesheet" type="text/css" />
<![endif]-->

Thanks in advance.

shin
  • 31,901
  • 69
  • 184
  • 271

4 Answers4

8

No, there are not.

You can hack it by doing browser detection in JS and attaching scripts/styles dynamically.

Or, if you are concerned only with having different css for different browsers, you can use css hacks. There are probably css hacks that work with the browsers you need.

Or, if the only thing you need to change is 'width' (of one css definition?) you can probably do it in jquery or javascript

jquery browser detection. see: http://docs.jquery.com/Utilities/jQuery.browser

mkoryak
  • 57,086
  • 61
  • 201
  • 257
  • 1
    yes. try $.browser.msie == true. $.browser.mozilla == true etc. inspect the $.brower object or read docs – mkoryak Jan 12 '10 at 21:12
  • After reading your reply, I found this and it works well. Thanks. http://www.tvidesign.co.uk/blog/CSS-Browser-detection-using-jQuery-instead-of-hacks.aspx – shin Jan 12 '10 at 21:14
  • But if I use email template and want to detect iPhone? I can't use scripts. Is there any way to hide or show some html markup specially designed for iPhone? – Pal May 13 '15 at 07:42
2

I use this on every project: http://rafael.adm.br/css_browser_selector/

Although, if you are having to do a lot of targeting in Firefox or Webkit — you may want to reconsider how you are writing your HTML/CSS.

scott
  • 21
  • 1
2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Browsser Detection</title>

<link rel="stylesheet" href="Main.css" type="text/css">

<?php 

$msie        = strpos($_SERVER["HTTP_USER_AGENT"], 'MSIE') ? true : false; 
$firefox    = strpos($_SERVER["HTTP_USER_AGENT"], 'Firefox') ? true : false;
$safari        = strpos($_SERVER["HTTP_USER_AGENT"], 'Safari') ? true : false;
$chrome        = strpos($_SERVER["HTTP_USER_AGENT"], 'Chrome') ? true : false;

if ($msie) {
echo '
<!--[if IE 7]>
<link rel="stylesheet" href="ie7.css" type="text/css">
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" href="ie8.css" type="text/css">
<![endif]-->
';
}
if ($safari) {
echo '<link rel="stylesheet" href="safari.css" type="text/css">';
}

?>

</head>
<body>

    <br>
    <?php
    if ($firefox) { //Firefox?
    echo 'you are using Firefox!';
    }

    if ($safari || $chrome) { // Safari?
    echo 'you are using a webkit powered browser';
    }

    if (!$msie) { // Not IE?
    echo '<br>you are not using Internet Explorer<br>';
    }
    if ($msie) { // IE?
    echo '<br>you are using Internet Explorer<br>';
    }
    ?>

    <br>

</body>
</html>

From Chrome conditional comments

Community
  • 1
  • 1
0

A CSS based solution was answer here. And its support accross webkit browsers is pretty broad.

Community
  • 1
  • 1
Oriol
  • 11,660
  • 5
  • 35
  • 37