2

How can I display a DIV which is bigger than its ancestor, when the ancestor DIV has style overflow: hidden; position: relative;?

Here is an example:

HTML:

<div class="container">
  <div class="content">
  __________________________SHOW_ME
  </div>
</div>

CSS:

.container {
  position: relative;
  padding: 10px;
  overflow: hidden;
  width: 10em;
  border: 1px solid;
  height: 50px;
}

.content {
  position: absolute;
  overflow: visible;
  border: 5px solid red;
}

Here is this example on JS Fiddle.

I tried styling the content DIV with various combinations of position: absolute, overflow: visible, right: -100px, but it didn't help.

How can I style the content div so that it is entirely visible? I cannot modify the parent DIV with container class, only the content inside.

TMG
  • 2,620
  • 1
  • 17
  • 40
  • 5
    short version: you can't. long version: you can use position fixed, but then the content div will scroll with the screen – Pete Sep 28 '16 at 13:02
  • 2
    i think, that you have to somehow modify `.container` to `overflow:visible` or its width – Pepo_rasta Sep 28 '16 at 13:02
  • @Pete thanks, position:fixed would work for me. Would you post that as Answer ? – TMG Sep 28 '16 at 13:10
  • 1
    Ah, give it to Erikzy - I don't think it's a good enough solution to warrant a full answer because of the scrolling defect - if I were to use js to fix that, instead, I would probably just wrap the container and move the content into the wrapper – Pete Sep 28 '16 at 13:14
  • Why do you need (or can't remove) `overflow: hidden` on the parent? – Asons Sep 28 '16 at 19:29
  • Check this answer in the dupe link: http://stackoverflow.com/a/11833892/2827823 – Asons Sep 28 '16 at 19:38

3 Answers3

0

if you want the content's position to be tied to the container, you basically can't unless you use javascript to update the position on scroll and set the position of the content to be fixed instead of absolute.

Erikzy
  • 26
  • 1
0

Actually you can't show div inside element using overflow:hidden, But I have solution for you. You can give your div with overflow:auto, so user can scroll x

Here the example fiddle

Rohman HM
  • 2,539
  • 3
  • 25
  • 40
0

.container {
  position: relative;
  padding: 10px;
  overflow: hidden;
  width: auto;
  border: 1px solid;
  height: 50px;
}

.content {
    position: absolute;
    overflow: auto;
    border: 5px solid red;
    width: auto;
    padding: 10px;
}
<div class="container">
  <div class="content">
        __________________________SHOW_ME
  </div>
</div>
Dhaarani
  • 1,350
  • 1
  • 13
  • 23