How to set media query for safari web browser

断了今生、忘了曾经 提交于 2021-02-07 20:24:16

问题


@media only screen and (min-width: 480px) and (max-width: 767px) {
}

Here is my media query how to fix it. how to set for safari web browser.


回答1:


Media queries aren't made for browser detection. Use javascript instead, for example:

if (navigator.userAgent.search("Safari") >= 0 && navigator.userAgent.search("Chrome") < 0) 
{
   alert("Browser is Safari");          
}

From this point you could set a class on the body tag to indicate a safari browser.

if (navigator.userAgent.search("Safari") >= 0 && navigator.userAgent.search("Chrome") < 0) 
{
   document.getElementsByTagName("BODY")[0].className += " safari";
}

Then you can use your CSS to target only safari elements like so:

body.safari h1{
    color: cyan;
}

More discussion on detecting the browser can be found here



来源:https://stackoverflow.com/questions/29120893/how-to-set-media-query-for-safari-web-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!