简体   繁体   English

为什么在使用inline-flex和min-height时会出现垂直滚动条:100%而Edge中存在水平滚动条?

[英]Why does a vertical scrollbar appear when using inline-flex and min-height: 100% while a horizontal scrollbar is present in Edge?

Here's a pen illustrating the issue: http://codepen.io/derrikcurran/pen/XNmEOZ 这是一个说明问题的笔: http//codepen.io/derrikcurran/pen/XNmEOZ

The browsers I'm worried about for now are Chrome, Firefox, and Edge. 我现在担心的浏览器是Chrome,Firefox和Edge。

I have a tree of 3 divs; 我有一个3 div的树; #grandparent > #parent > #child. #grandparent> #parent> #child。 If #grandparent has overflow: auto and #parent has display: inline-flex and min-height: 100% , it seems to work well in all 3 browsers. 如果#grandparent有overflow: auto和#parent有display: inline-flexmin-height: 100% ,它似乎在所有3个浏览器中运行良好。 However, if #child is wider than #parent, a horizontal scrollbar appears on #grandparent (as expected and desired) and, only in Edge, a vertical scrollbar appears as well. 但是,如果#child比#parent宽,则#grandparent上会出现一个水平滚动条(正如所期望的那样),并且只有在Edge中,才会出现垂直滚动条。

It seems that the minimum height calculation in Edge is not taking the height of the horizontal scrollbar into account. 似乎Edge中的最小高度计算没有考虑水平滚动条的高度。 In fact, Edge's horizontal scrollbar is 12px tall and min-height: calc(100% - 12px) solves the problem. 事实上,Edge的水平滚动条高12px, min-height: calc(100% - 12px)解决了这个问题。

Is there some way to work around this without useragent sniffing or Javascript? 有没有办法在没有使用嗅探或Javascript的情况下解决这个问题? Is it a bug with Edge? 这是Edge的错误吗? To be clear, I need #grandparent to scroll in both directions, but only when #child is taller than #parent. 要清楚,我需要#grandparent向两个方向滚动,但只有当#child比#parent高时才需要。

I'd like to point out that this does not appear to be caused by the well known IE11 flexbox/min-height issue described here: https://connect.microsoft.com/IE/feedback/details/802625/ 我想指出,这似乎不是由这里描述的众所周知的IE11 flexbox / min-height问题引起的: https ://connect.microsoft.com/IE/feedback/details/802625/

  #grandparent {
    position: absolute;
    top: 20px;
    right: 0;
    bottom: 0;
    left: 0;
    overflow-x: hidden; /* Your solution */
    overflow-y: auto; /*Other half */
}

I fixed your overflow, so the page doesn't scroll. 我修复了你的溢出,所以页面不滚动。 If you want no scroll bars use "Hidden" for both. 如果您不想滚动条,请使用“隐藏”。

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

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