css - Absolutely positioned element positions relatively to transformed element -


i recreated issue encountering in template. there nav has position: relative;. inside nav there div 2 lists nested.
1 of lists position absolutely stick bottom of nav. problem occurs when div has transformation applied it.
when div in between absolutely , relatively positioned elements get's transform property, absolute list positions relatively div instead of nav.

mdn docs state following position:absolute

do not leave space element. instead, position @ specified position relative closest positioned ancestor if any, or otherwise relative containing block. absolutely positioned boxes can have margins, , not collapse other margins.

does mean transformed element positioned element? why this? tested in edge, ff, , chrome. act same.

you can run recreated snippet below. applying transform on div on hover of nav.

*{    margin: 0;    padding: 0;    box-sizing: border-box;  }  html, body{    min-height: 100%;    height: 100%;  }  nav{    background: #000;    height: 100%;    width: 50%;    position: relative;  }  nav:hover > div{        transform: translatex(50px) translatey(0) translatez(0);  }  a{    color: #fff;  }  ul{    padding: 16px;  }  ul.main{    background: blue;  }    ul.lower{    position: absolute;    background: red;    bottom: 0;    width: 100%;  }
<!doctype html>  <html>  <head>    <meta charset="utf-8">    <meta name="viewport" content="width=device-width">    <title>js bin</title>  </head>  <body>  <nav>    <div>      <ul class="main">        <li><a href="">link</a></li>        <li><a href="">link</a></li>        <li><a href="">link</a></li>        <li><a href="">link</a></li>      </ul>      <ul class="lower">        <li><a href="">link</a></li>        <li><a href="">link</a></li>        <li><a href="">link</a></li>        <li><a href="">link</a></li>      </ul>    </div>  </nav>  </body>  </html>

basically because element transform property applied, automatically triggers new stacking order: https://developer.mozilla.org/en-us/docs/web/css/transform

"if property has value different none, stacking context created. in case object act containing block position: fixed elements contains."

here info stacking context: https://developer.mozilla.org/en-us/docs/web/css/css_positioning/understanding_z_index/the_stacking_context


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -