我想让身体拥有100%的浏览器高度.我可以使用CSS吗?
我试过设置height: 100%,但它不起作用.
我想为页面设置背景颜色以填充整个浏览器窗口,但如果页面内容很少,我会在底部看到一个丑陋的白色条.
我有一个非常奇怪的问题...在每个浏览器和移动版本中我遇到这种行为:
怎么能避免这个问题?当我第一次听到视口高度时,我很兴奋,我认为我可以将它用于固定高度块而不是使用javascript,但现在我认为唯一的方法是实际上javascript与一些resize事件......
任何人都可以帮我/建议一个CSS解决方案吗?
简单的测试代码:
/* maybe i can track the issue whe it occours... */
$(function(){
var resized = -1;
$(window).resize(function(){
$('#currenth').val( $('.vhbox').eq(1).height() );
if (++resized) $('#currenth').css('background:#00c');
})
.resize();
})Run Code Online (Sandbox Code Playgroud)
*{ margin:0; padding:0; }
/*
this is the box which should keep constant the height...
min-height to allow content to be taller than viewport if too much text
*/
.vhbox{
min-height:100vh;
position:relative;
}
.vhbox .t{
display:table;
position:relative;
width:100%;
height:100vh;
}
.vhbox .c{ …Run Code Online (Sandbox Code Playgroud)我必须在屏幕高度上安装iframe.显然,我想要100%的宽度,但由于这不起作用,我使用了100vh.但是vh像vw并不完全是100%.在我的笔记本电脑通过镀铬,而100%宽度完美呈现,而不需要水平滚动条,大众额外约1厘米.