简体   繁体   English

如果内容高于视口,则具有100vh的后备广告?

[英]100vh with fallback if content higher than viewport?

Content in the viewport is fluid so when viewed on a smaller device the content height exceeds the 100vh. 视口中的内容是流动的,因此,在较小的设备上查看时,内容高度超过100vh。 I was thinking of just using JS to calc the min-height of content blocks. 我当时正在考虑仅使用JS计算内容块的最小高度。 Any ideas on a straight on if there is CSS approach? 如果有CSS方法,有什么想法吗? Cannot think of much... but maybe other smart folks can :-) 想不到太多...但是也许其他聪明的人可以:-)

 .content.intro { height: 100vh; min-height: 800px; // content can be higher than this display: flex; align-items: center; justify-content: center; margin-top: -80px; padding-top: 80px; // adjust for the 80px header at top } 

Thanks for the comments. 感谢您的评论。 In this case it's a block of copy that can exceed the height of 100vh, because it's centered in flex layout it was clipping the text at smaller heights. 在这种情况下,它是一个副本块,可以超过100vh的高度,因为它位于flex布局的中心,因此会将文本剪切到较小的高度。 My solution was just some simple JS triggered on load and resize: 我的解决方案是在加载和调整大小时触发一些简单的JS:

 setMinHeight : function() { $('.content.intro').each(function() { var bodyCopy = $(this).find('.bodyCopy'), padTop = $(this).css('padding-top').substring(0,2), padBottom = $(this).css('padding-bottom').substring(0,2); minHeight = bodyCopy.outerHeight(true) + parseInt(padTop) + parseInt(padBottom) + $('header').outerHeight(); $(this).css( { 'min-height' : minHeight + 'px' }); }); } 

Basically just set min-height of bodyCopy so the viewport is never smaller that the content inside it. 基本上只设置bodyCopy的最小高度,这样视口就不会比其内部内容小。

In my case -> content height + top/bottom padding of parent + height of header to stop overlapping 就我而言->内容高度+父级的顶部/底部填充+标头的高度以停止重叠

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM