3

I'm trying to make a website that is essentially a few vertically positioned slides. I had been hoping to make a responsive design so my "slides" are appropriately resized on larger screen sizes or are padded appropriately in strange dimensions. Here is my LESS file setting the appropriate dimensions:

html, body {
    width: 100%; 
    height: 100%;
    padding: 0;
    margin: 0;
}
//============================================================
// Dimensions for each section for standard desktop screen
//============================================================

#home {
    @media screen and (min-aspect-ratio: 16/10) {
        height: 92%;
        width: 160vh;
        padding: 0 calc(50% - 80vh);
    }

    @media screen and  (max-aspect-ratio: 16/10) {
        width: 100%;
        height: 57.5vw;
    }
}

#about {
    @media screen and (min-aspect-ratio: 16/10) {
        height: 108%;
        width: 160vh;
        padding: 0 calc(50% - 80vh)
    }

    @media screen and (max-aspect-ratio: 16/10) {
        width: 100%;
        height: 67.5vw;
    }
}

#experience, #hobbies, #contact {
    @media screen and (min-aspect-ratio: 16/10) {
        height: 100%;
        width: 160vh;
        padding: 0 calc(50% - 80vh);
    }

    @media screen and (max-aspect-ratio: 16/10) {
        width: 100%;
        height: 62.5vw;
    }
}

//============================================================
// colors
//============================================================

#home {
    background-color: black;
}

#about {
    background-color: #488BFF;
}

#experience {
    background-color: #B3B3B3;
}

#hobbies {
    background-color: #FF7F35;
}

#contact {
    background-color: #803A7D;
}

It seems to work for the most part when I run it with a simple html file with the 5 divs (home, about, experience, hobbies, contact). However, on chrome, a bug seems to occur while I resize. Sometimes, my webpage simply disappears, replaced with some black/gray cross. If I resize very quickly (rapidly resizing the window), a checkerboard appears or even some other webpage completely on a different tab. I tried testing resizing another webpage also using media queries, and this problem did not happen. Is there something inherently wrong with how I'm using media queries?

EDIT: Sample images showing the strange problems:

Windows cross Mac checkerboard-ish

ImpGuard
  • 885
  • 2
  • 13
  • 18
  • The checkerboard is normal if the reflow is taking too long. It means that there is simply nothing being displayed on it. Some image editing programs use this to show transparency. This issue used to happen A LOT with older iphones and ipods. Try to change your units to em's or percentages. – Ismael Miguel Dec 26 '14 at 00:51
  • When I say checkerboard, I'm talking about a black screeen with white squares going across a diagonal. Not the full screen checkerboard like the old iphones. Also, it seems to generate a black and gray cross on my windows desktop (but not on my Mac). Simply an enormous black gray cross. Added some pictures to the original post. – ImpGuard Dec 26 '14 at 00:59
  • Do you have an nvidia card? There are a few visual bugs with nvidias on windows 8 with chrome. You should try to update the drivers. I had a client coming with chrome showing ALL webpages as pink – Ismael Miguel Dec 26 '14 at 01:04
  • Yes, I do on my windows computer. However, it's only one driver old (updating now), so I doubt that it's the problem (gamer here, haha). Though, it doesn't explain the mac problem. Could this simply be a chrome issue? It seems to work fine in firefox and even IE. – ImpGuard Dec 26 '14 at 01:08
  • Can you try to assemble a fiddle showing the issue, please? I can try on my computer and I will give a better reason after. But the only thing I can think of is graphic issues and problems with the viewport unit. – Ismael Miguel Dec 26 '14 at 01:11
  • JSFiddle: http://jsfiddle.net/7myszjwc/ I made it, but testing it on my desktop or my mac does not reproduce the issue. I'm currently running the code via a simple static webserver to testing purposes over my home network. On both laptops it produces the different issues noted above. Thanks a lot by the way! – ImpGuard Dec 26 '14 at 01:18
  • I can't reproduce the issue using chrome 39.0.2171.95 m. But what is your goal with the design? To make all the divs to occupy 100% of the window size? But keep aspect ration? – Ismael Miguel Dec 26 '14 at 01:26
  • So maybe its just some internal problem that I shouldn't worry about? And yes I'm essentially trying to set my divs such that the largest 16:10 ratio rectangle can fit inside my viewport, except for the first two divs where the first is slightly shorter and the second is slightly taller. Is there a better and less prone to error method? Preferably just using css. – ImpGuard Dec 26 '14 at 01:38
  • The only way I can think of (to avoid using `vw` and `vh`) is percentages. What I had done once, to a question where 5 divs had to take 100% of the screen size, was to make a huge div with 500% of the height and 100% of the width. Then I set `100/ %` as the height for the inner divs. This proved to be reliable even in quirks mode. You can check here how I did it: http://stackoverflow.com/questions/25773801/responsive-height-for-single-page-website/25909351#25909351. To make it work the way you want, you have to play with the height of the elements and media queries of your code – Ismael Miguel Dec 26 '14 at 01:52
  • I've managed to reproduce it. It really is a problem with chrome. If you open the element inspector and you disable the background of one of the pages, you will see that the bug goes away and the page shows normally. If you, on the `height`, replace `vw` with `vh`, the issue "goes away" and only shows up when you resize REALLY fast in a short space. Another strange behavior is that ALL element's background change to black. – Ismael Miguel Dec 26 '14 at 02:02
  • I've sorted out the issue! It is the use of `vw` in `height`. I will post the answer. – Ismael Miguel Dec 26 '14 at 02:07

1 Answers1

3

After a long and arduous chat session, we have worked out a fix for the bug. Here is the summary:

What's Wrong

For some reason, Chrome has a problem rendering large divs. As of now, I'm not sure where the bug lies exactly, but a simple example with 5 100% width/height divs causes this strange problem. Here is a JSFiddle with this example. The bug only manifests outside of a frame, so you must copy the frame source into its own webpage.

From what I can gather, something strange is happening under the hood in Chrome's rendering engine on Windows, which causes the strange black & gray crosses to appear when resizing a window.

The Fix

The fix isn't very elegant, but it works. Simply apply a transform:rotate(0) on each of the divs to force gpu acceleration. With this, the cross vanishes. Here is the resulting JSFiddle that applies this fix on the previous example.


TL;DR

When Chrome isn't rendering the pages with the graphics card, strange things occur. Use transform:rotate(0) on broken items to force graphic card rendering.

ImpGuard
  • 885
  • 2
  • 13
  • 18
Ismael Miguel
  • 4,185
  • 1
  • 31
  • 42
  • Will test when I return to my computer and credit you! Thanks! Ill probably just ignore it and return to these workarounds if problem still exists when I finish development. – ImpGuard Dec 26 '14 at 02:43
  • @ImpGuard If you really are able to ignore this, you deserve a cookie for your strong willpower. I couldn't ignore such a bug. But as a temporary fix, you really can set `transform: rotateZ(0deg);` to the `` and you don't need to 'ignore' it. – Ismael Miguel Dec 26 '14 at 02:46
  • Haha I'm ok since its technically not my bug and doesn't appear on other browsers. Yea that would work though! – ImpGuard Dec 26 '14 at 02:48
  • @ImpGuard I hope you have a nice session of coding now. And please, consider using percentages for now, or you can check http://stackoverflow.com/questions/13948713/is-there-any-cross-browser-javascript-for-making-vh-and-vw-units-work but if you use the javascript code, use the one here: http://jsbin.com/ugefub/1/edit#javascript. Checking http://caniuse.com/#feat=viewport-units you will see that there are some issues with iOS, IE9 and Firefox mobile. – Ismael Miguel Dec 26 '14 at 02:56
  • Hmm, how will percentages work without js? You cant ensure an aspect ratio can you? – ImpGuard Dec 26 '14 at 02:59
  • @ImpGuard The first link is a solution to use the `vw` unit in all browsers, even the ones that don't support it. The 2nd link is the version in one of the comments, which fixed an issue and I confirm that it works. The 3rd link is to show the current support level, which is quite 'acceptable'. About percentages, you can't be 100% that the aspect ratio will be kept. You can try to use the media queries you used on your css and try to force an aspect ratio. Using percentages doesn't require any javascript but you need a lot of focusing. To have perfect aspect ratios, you can use javascript. – Ismael Miguel Dec 26 '14 at 03:02
  • Unfortunately, the black cross still appears on windows even with some fixes. I've recoded everything in JS, and it still appears. I'll probably make it a separate question since the details are slightly more specific. Thanks though! – ImpGuard Dec 26 '14 at 06:29
  • @ImpGuard You are welcome. If you post a question, please add here the link to check it. Or add another printscreen here of the red cross issue. I will take a look at it. – Ismael Miguel Dec 26 '14 at 09:11
  • Here's a link to the other question: http://stackoverflow.com/questions/27653695/windows-chrome-black-cross – ImpGuard Dec 26 '14 at 22:52
  • @ImpGuard That is the issue I got and that's the one I'm talking about here in this answer... :/ The other issue on your mac is a "collateral damage" that might be fixed in the same way. – Ismael Miguel Dec 26 '14 at 22:56
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/67735/discussion-between-impguard-and-ismael-miguel). – ImpGuard Dec 26 '14 at 22:57