【问题标题】:Flexbox overlapping absoluted positioned childrensFlexbox 重叠绝对定位子级
【发布时间】:2016-08-11 10:34:07
【问题描述】:

我遇到了flexbox 带有绝对定位子级的容器的问题。

FIDDLE;如果窗口变小(宽度)标题变小,那是绝对正确的,问题出在与其他手表重叠的数字上。我对z-Indexbackground-color 进行了一些测试,但没有任何效果。

HTML:

<div class="stopwatch">
    <div class="stopwatch__panel">
        <div class="stopwatch__header">
            <div class="stopwatch__title">Random Title 404531</div>
        </div>
        <div class="stopwatch__body">
            <div class="stopwatch__counter">
                <div class="stopwatch__segment stopwatch__segment--five">
                    <div class="stopwatch__segmentTopLeft"></div>
                    <div class="stopwatch__segmentTop"></div>
                    <div class="stopwatch__segmentTopRight"></div>
                    <div class="stopwatch__segmentMiddle">
                        <div class="stopwatch__segmentMiddleTop"></div>
                        <div class="stopwatch__segmentMiddleBottom"></div>
                    </div>
                    <div class="stopwatch__segmentBottomLeft"></div>
                    <div class="stopwatch__segmentBottom"></div>
                    <div class="stopwatch__segmentBottomRight"></div>
                </div>
                <div class="stopwatch__segment stopwatch__segment--five">
                    <div class="stopwatch__segmentTopLeft"></div>
                    <div class="stopwatch__segmentTop"></div>
                    <div class="stopwatch__segmentTopRight"></div>
                    <div class="stopwatch__segmentMiddle">
                        <div class="stopwatch__segmentMiddleTop"></div>
                        <div class="stopwatch__segmentMiddleBottom"></div>
                    </div>
                    <div class="stopwatch__segmentBottomLeft"></div>
                    <div class="stopwatch__segmentBottom"></div>
                    <div class="stopwatch__segmentBottomRight"></div>
                </div>
            </div>
        </div>
    </div>
    <div class="stopwatch__panel">
        <div class="stopwatch__header">
            <div class="stopwatch__title">Random Title 714895</div>
        </div>
        <div class="stopwatch__body">
            <div class="stopwatch__counter">
                <div class="stopwatch__segment stopwatch__segment--nine">
                    <div class="stopwatch__segmentTopLeft"></div>
                    <div class="stopwatch__segmentTop"></div>
                    <div class="stopwatch__segmentTopRight"></div>
                    <div class="stopwatch__segmentMiddle">
                        <div class="stopwatch__segmentMiddleTop"></div>
                        <div class="stopwatch__segmentMiddleBottom"></div>
                    </div>
                    <div class="stopwatch__segmentBottomLeft"></div>
                    <div class="stopwatch__segmentBottom"></div>
                    <div class="stopwatch__segmentBottomRight"></div>
                </div>
            </div>
        </div>
    </div>
</div>

CSS:

.stopwatch {
    position: fixed;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
    max-width: 100%;
    width: 100%;
}

.stopwatch__panel {
    background-color: #ffffff;
    border: 1px solid #dddddd;
    display: flex;
    flex-flow: column;
    min-width: 0;
}

.stopwatch__header {
    background-color: #f5f5f5;
    display: flex;
    align-items: center;
    order: 1;
}

.stopwatch__title {
    flex: 1 1 auto;
    padding: 5px;
    border-left: 1px solid #dddddd;
    word-wrap: break-word;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stopwatch__body {
    display: flex;
    align-items: stretch;
}

.stopwatch__counter {
    background-color: #333333;
    padding: 15px;
    flex-grow: 1;
    text-align: center;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stopwatch__segment {
    position: relative;
    float: left;
    margin: 6px;
    width: 18px;
    height: 35px;
    transition: all 200ms ease-in-out;
}

.stopwatch__segment--zero .stopwatch__segmentTopRight {
    border-right-color: #e6e6e6;
}
/* [...all numbers from zero to nine... (only coloring borders) ] */
.stopwatch__segment--nine .stopwatch__segmentBottom {
    border-bottom-color: #e6e6e6;
}

.stopwatch__segmentTop {
    position: absolute;
    left: 1px;
    height: 0;
    width: 10px;
    border-top: 3px solid #424242;
    border-left: 3px solid transparent;
    border-right: 3px solid transparent;
    transition: all 200ms ease-in-out;
}

.stopwatch__segmentTopRight {
    position: absolute;
    left: 15px;
    top: 1px;
    height: 10px;
    width: 0;
    border-right: 3px solid #424242;
    border-top: 3px solid transparent;
    border-bottom: 3px solid transparent;
    transition: all 200ms ease-in-out;
}
/* [... the other segments parts ...] */

【问题讨论】:

  • 我不确定您期望会发生什么。绝对定位将发挥它的作用。我不确定 flexbox 可以做些什么来改变这一点,
  • @Paulie_D 我不知道问题出在哪里,flexbox 还是绝对定位。你没看到重叠的(图片)吗?

标签: css css-position flexbox z-index absolute


【解决方案1】:

overflow:hidden; 添加到.stopwatch__counter

.stopwatch__counter {
    background-color: #333333;
    padding: 15px;
    flex-grow: 1;
    text-align: center;
    color: #ffffff;
    display: flex;
    overflow:hidden;
    align-items: center;
    justify-content: center; }

看到这个小提琴: https://jsfiddle.net/grassog/jcgyce3g/2/

【讨论】:

  • 我想,我失去了概述!我另外将width.stopwatch_segment 更改为min-width 谢谢! +1
猜你喜欢
  • 1970-01-01
  • 2013-03-11
  • 1970-01-01
  • 1970-01-01
  • 2015-07-18
  • 2020-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多