Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8483375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:05:09+00:00 2026-06-10T20:05:09+00:00

Is there a simple conditional statement, css command, html, jquery, javascript or simple PHP

  • 0

Is there a simple conditional statement, css command, html, jquery, javascript or simple PHP dynamic way of detecting the current browser?

<!if firefox>
    .element { top:4px; }
<![endif]>
<!if chrome>
    .element { top:6px; }
<![endif]>
<!if ie>
    .element { top:8px; }
<![endif]>
<!if opera>
    .element { top:10px; }
<![endif]>
<!if safari_webkit>
    .element { top:12px; }
<![endif]>

Can this Psuedo code be done in jQuery/JS/HTML or CSS PHP etc?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:05:11+00:00Added an answer on June 10, 2026 at 8:05 pm

    With CSS there is no way you can achieve browser detection.
    However with PHP, ASP and other programming languages you can get browser detection within the page. I am not here to tell you the pro or cons about it – I take it you know about the bad and good about browser detection and web standards but here is the list.

    PHP solution.

    if(isset($_SERVER['HTTP_USER_AGENT'])){
        $agent = $_SERVER['HTTP_USER_AGENT'];
    }
    

    Then, compare it to what you want

    For compare with, for example “firefox” you should do:

    if(strlen(strstr($agent,"Firefox")) > 0 ){      
        $browser = 'firefox';
    }
    if($browser=='firefox'){
        echo '<style type="text/css">.element{top:2px}';
    }
    

    jQuery solution.

    // Safari CSS and Webkit Google Chrome
    if ($.browser.webkit) {
       $("#element").css('top', '2px');
    } else if ( $.browser.safari ) //not fully supported on 1.7 jQuery {
       $("#element").css('top', '2px');
    // Opera CSS
    } else if ( $.browser.opera ) {
       $("#element").css('top', '2px');
    // Internet Explorer CSS
    } else if ( $.browser.msie ) {
       $("#element").css('top', '2px');
    // Mozilla FireFox CSS
    } else if ( $.browser.mozilla ) {
       $("#element").css('top', '2px');
    // Normal Revert, careful and note your the use of !important
    } else {
       $("#element").css('top', '2px');
       // You can have normal JavaScript between these too
       document.getElementById("element").style.top="2px";
    }
    

    Mootools solution.

    if (Browser.ie){
        // This code will only run in IE
    }
    
    if (Browser.firefox2){
        // This code will only run in Firefox 2
    }
    if (Browser.firefox){
        // This code will only run in Firefox 
    } 
    if (Browser.chrome){
        // This code will only run in Chrome
    } 
    if (Browser.opera){
        // This code will only run in Chrome
    }   
    if (Browser.ie6 || Browser.ie7){
        // Please upgrade your browser
    }
    // Also notice you can use Engine.trident
    if(Browser.Engine.trident) {
    
    }
    

    Prototype solution.

    if(Prototype.Browser.IE){
      // do something IE specific
    }
    if(Prototype.Browser.Opera){
      // do something Opera specific
    }
    if(Prototype.Browser.WebKit){
      // do something WebKit specific
    }
    if(Prototype.Browser.MobileSafari){
      // do something MobileSafari specific - iPhone etc
    }
    if(Prototype.Browser.Gecko){
      // do something Gecko specific
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a simple way to insert the current time (like TIME: [2012-07-02 Mon
Is there a simple way, possibly with open-source command line tools in Linux, to
Is there a simple way to use a typedef based on an if condition?
Is there a simpler way to rewrite the following condition in JavaScript? if ((x
Is there a simple way to serialize a single-level structure as a string for
Is there a simple way in Symfony 1.4 to know whether a submitted form
Is there an analogous conditional-not-present attribute or maybe a way to use the Conditional
Are there simple libraries out there (.NET and Java) that are able to validate
There is simple cipher that translates number to series of . ( ) In
There is simple JSON serialization module with name simplejson which easily serializes Python objects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.