Jump to content
  • 0

Is It Possible To Apply Css Styles Depends On Browser?



1 answer to this question

Recommended Posts

  • 0

Hello Cameron,


How are you doing?


I think, you can use the following code:

var sheet = document.createElement('style');
     if((navigator.userAgent.indexOf("Opera") || navigator.userAgent.indexOf('OPR')) != -1 )
        sheet.innerHTML = "input[type=text] {color: red !important;}"; //Opera
    else if(navigator.userAgent.indexOf("Chrome") != -1 )
        sheet.innerHTML = "input[type=text] {color: purple !important;}"; //Chrome
    else if(navigator.userAgent.indexOf("Safari") != -1)
         sheet.innerHTML = "input[type=text] {color: blue !important;}"; //Safari
    else if(navigator.userAgent.indexOf("Firefox") != -1 )
         sheet.innerHTML = "input[type=text] {color: red !important;}"; //Firefox
    else if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )) //IF IE > 10
      sheet.innerHTML = "input[type=text] {color: orange !important;}"; //IE
       sheet.innerHTML = "input[type=text] {color: black !important;}"; //other

If you want do not use any browser, you can add "//" before the line for this browser, for example:

//sheet.innerHTML = "input[type=text] {color: red !important;}"; //Opera


Also you can add more than one setting:

sheet.innerHTML = "input[type=text] {color: red !important; background-color: black !important;}"; //Firefox

Have a good day!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...