有人知道Safari vh规则是否有修复?
#what{ min-height:70vh; }
一切正常,在所有浏览器中,但仅在Safari中无法识别?
是否有针对safari的修复,我们可以在css中使用VH规则?
解决方法
而不是Vw / Vh,使用这个JavaScript的rem. “运行代码片段”可能会造成混淆,导致其窗口通过缩放“调整大小”.要测试这一点,只需将此代码复制到某个html文件中,然后在Safari和其他浏览器中运行(或参见“整页”).
<!DOCTYPE html> <head> <script language="javascript" type="text/javascript"> (function (doc,win) { var docEl = doc.documentElement,recalc = function () { var clientWidth = docEl.clientWidth; if (!clientWidth) return; docEl.style.fontSize = clientWidth + 'px'; docEl.style.display = "none"; docEl.clientWidth; // Force relayout - important to new Android devices docEl.style.display = ""; }; // Abort if browser does not support addEventListener if (!doc.addEventListener) return; // Test rem support var div = doc.createElement('div'); div.setAttribute('style','font-size: 1rem'); // Abort if browser does not recognize rem if (div.style.fontSize != "1rem") return; win.addEventListener('resize',recalc,false); doc.addEventListener('DOMContentLoaded',false); })(document,window); </script> <style> @charset "utf-8"; *{padding: 0;margin: 0;} div {position:fixed;width:40%;height:30%;background-color:yellow;color:blue;font-size:0.02rem;} </style> </head> <body> <div>in this case 0.01 rem == 1vw . You need to remove body margins.</div> </body> </html>
有关更多信息,请参阅我发现的这篇文章.
http://css-tricks.com/theres-more-to-the-css-rem-unit-than-font-sizing