代码之家  ›  专栏  ›  技术社区  ›  Willege

在CSS3转换中,子级不会与父级一起转换

  •  0
  • Willege  · 技术社区  · 10 年前

    为了将一个元素完全转换到视图之外,我使用了 transform: translate(0, -100%); 。但是,如果将窗口的大小调整到足够高,则其子窗口将逐渐重新出现。我不知道他们为什么这么做,我希望有人能解释为什么会这样。这是 the fiddle .

    HTML格式

    <body>
        <div id="background">
             <div id="circle1"></div>
             <div id="circle2"></div>
        </div>
    </body>
    

    CSS公司

    html, body {
        height: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
    }
    
    #background {
        background-color: red;
        height: 100%;
        width: 100%;
        position: fixed;
        transform: translate(0, -100%);
    }
    
    #circle1 {
        background-color: yellow;
        height: 500px;
        width: 500px;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        margin: auto;
        position: fixed;
        border-radius: 50%;
        z-index: 0;
    }
    
    #circle2 {
        background-color: aqua;
        height: 400px;
        width: 400px;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        margin: auto;
        position: fixed;
        border-radius: 50%;
        z-index: 1;
    }
    
    1 回复  |  直到 10 年前
        1
  •  1
  •   Johannes    10 年前

    你的圆圈有固定的高度(500px/400px)。什么时候 #background 的高度小于窗口的大小,圆圈将溢出 #背景 垂直地 这个 translate 移动100%是指 #背景 ,所以你仍然可以看到圆圈会溢出的部分 #背景 没有 翻译 背景