Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parent & child with position fixed, parent overflow:hidden bug

I don't know if there is an issue, but I was wondering why the overflow:hidden does not function on fixed parent/children element.

Here's an example:

CSS and HTML:

.parent{    position:fixed;    overflow:hidden;    width:300px;    height:300px;    background:#555;  }  .children{    position:fixed;    top:200px;    left:200px;    width:150px;    height:150px;    background:#333;  }
<div class="parent">    <div class="children">    </div>  </div>

Live demo: jsFiddle

like image 557
kirkas Avatar asked Sep 17 '12 16:09

kirkas


People also ask

What is the full meaning of parent?

What does PARENT mean? parent(noun) a father or mother; one who begets or one who gives birth to or nurtures and raises a child; a relative who plays the role of guardian.

Which is correct parent or parents?

Parents is the plural form of parent. Parents' is the possessive form referring to more than one parent. Parent's means belonging to one parent in writing English and parents' means belonging to more than one parent. Whenever we talk about plural possessions, apostrophe ( ' ) goes at the very end.

How do you define your parents?

A parent is a mother or father. Your mom and your dad are your parents, and one of their jobs is to parent you. We're all born to parents, and many of us also have step parents, foster parents, or adoptive parents who parent us.

Who is considered a parent?

The father and mother whose DNA a child carries are usually called the child's biological parents. Legal parents have a family relationship to the child by law, but do not need to be related by blood, for example in the case of an adopted child.


2 Answers

You could consider using CSS clip: rect(top, right, bottom, left); to clip a fixed positioned element to a parent. See demo at http://jsfiddle.net/lmeurs/jf3t0fmf/.

Beware, use with care!

Though the clip style is widely supported, main disadvantages are that:

  1. The parent's position cannot be static or relative (one can use an absolutely positioned parent inside a relatively positioned container);
  2. The rect coordinates do not support percentages, though the auto value equals 100%, ie. clip: rect(auto, auto, auto, auto);;
  3. Possibillities with child elements are limited in at least IE11 & Chrome34, ie. we cannot set the position of child elements to relative or absolute or use CSS3 transform like scale.

See http://tympanus.net/codrops/2013/01/16/understanding-the-css-clip-property/ for more info.

EDIT: Chrome seems to handle positioning of and CSS3 transforms on child elements a lot better when applying backface-visibility, so just to be sure we added:

-webkit-backface-visibility: hidden; -moz-backface-visibility: hidden; backface-visibility: hidden; 

to the main child element.

Also note that it's not fully supported by older / mobile browsers or it might take some extra effort. See our implementation for the menu at bellafuchsia.com.

  1. IE8 shows the menu well, but menu links are not clickable;
  2. IE9 does not show the menu under the fold;
  3. iOS Safari <5 does not show the menu well;
  4. iOS Safari 5+ repaints the clipped content on scroll after scrolling;
  5. FF (at least 13+), IE10+, Chrome and Chrome for Android seem to play nice.

EDIT 2014-11-02: Demo URL has been updated.

like image 77
lmeurs Avatar answered Sep 20 '22 00:09

lmeurs


Because a fixed position element is fixed with respect to the viewport, not another element. Therefore since the viewport isn't cutting it off, the overflow becomes irrelevant.

Whereas the position and dimensions of an element with position:absolute are relative to its containing block, the position and dimensions of an element with position:fixed are always relative to the initial containing block. This is normally the viewport: the browser window or the paper’s page box.

ref: http://www.w3.org/wiki/CSS_absolute_and_fixed_positioning#Fixed_positioning

like image 33
j08691 Avatar answered Sep 19 '22 00:09

j08691