简体   繁体   English

响应式网格高度问题

[英]Responsive Grid Height Issues

So I'm trying to make a responsive grid layout for a web re-design I am working on. 因此,我正在尝试为正在处理的Web重新设计响应式网格布局。 I started to lay out some placeholders, which can be found in a jsfiddle here . 我开始布置一些占位符,可以在这里的jsfiddle中找到它们

The width works great; 宽度很好; exactly how I want it to. 正是我想要的。

.half-cell {

        height:70%;

        width:50%;
        background-color: #458bff;
        float: left;
        display:inline;

        background-size:cover;


        }

        .quarter-cell-horiz {
            height:35%;                
            width:50%;
            float: left;
            display:inline;
            background-color:#373737;

        }

However, I am noticing some issues with my height. 但是,我注意到我的身高有些问题。 I'm noticing that at some heights, the placeholders jump out of place. 我注意到,在某些高度,占位符会跳出位置。 I figure this is because it can't measure out a perfect 70% at every height, the way it can a 50% width. 我认为这是因为它无法在每个高度上都测量出理想的70%,而在50%的宽度下却无法测量出完美的70%。

I'm trying to find a way I can prevent that from happening, while maintaining a specific ratio with each of my placeholders. 我试图找到一种方法来防止这种情况的发生,同时与每个占位符保持特定的比例。 Preferably, I would like to do so using CSS. 最好是,我想使用CSS。

Any help y'all could provide would be great. 你们所有人都可以提供的任何帮助都会很棒。 Thank you for looking at this! 感谢您的关注!

DEMO 演示

Just like 100% width is equal to windows width we have to make sure height does the same! 就像100%的宽度等于窗口的宽度一样,我们必须确保高度相同! by applying this css: 通过应用此CSS:

html, body{ height: 100%; }

Will make sure that any element that you give height in percentage will depend on window height unless its parent have specific height defined (must be first level child of body). 将确保您以百分比形式给出的任何高度的元素都将取决于窗口高度,除非其父级定义了特定的高度(必须是body的第一级子级)。

I have created a class named vertical-row which will create 100% height section which you can then use to define 50% height and so on within it for each row you have. 我创建了一个名为vertical-row的类,该类将创建100%高的部分,然后您可以使用该部分定义50%的高度,以此类推。 You can go on and make vertical-row-half to take 50% and so on for a vertical grid system. 您可以继续进行操作,使垂直行的一半减少50%,以此类推。

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

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