Cameron Posted December 18, 2015 Report Share Posted December 18, 2015 Hi everyone, I want to apply different CSS styles in different browsers. Is it possible? Thank you for your time! Quote Link to comment Share on other sites More sharing options...
0 Xiang Posted December 18, 2015 Report Share Posted December 18, 2015 Hello Cameron, How are you doing? I think, you can use the following code: <script> 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 } else { sheet.innerHTML = "input[type=text] {color: black !important;}"; //other } document.getElementsByTagName('head')[0].appendChild(sheet); document.head.appendChild(sheet); </script> 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! Quote Link to comment Share on other sites More sharing options...
Question
Cameron
Hi everyone,
I want to apply different CSS styles in different browsers.
Is it possible?
Thank you for your time!
Link to comment
Share on other sites
1 answer to this question
Recommended Posts
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.