0

I am working on a project where I am displaying messages when the user hovers over a box, I have created a scenario to mock up what I am having issues with.

The blue box should appear as the full 250px as defined and not be clipped to the 200px that the containing div is set to, is there anyway to get round this, I can sit the blue box outside the containing div as its all part of a UserControl that needs to be self contained.

#first {
    width: 200px;
    height: 200px;
    background-color: green;
    overflow: hidden;
}

#second {
    width: 50px;
    height: 50px;
    background-color: red;
    position: relative;
}

#fourth
{
    width: 250px;
    height: 50px;
    background-color: blue;
    position: absolute;
    z-index: 100;
}
<div id="first">
    <div id="second">
      <div id="fourth">
      test
      </div>      
    </div>
</div>

1
  • 1
    Remove #first{ overflow: hidden } because that is intended behavior and there is no work around apart from changing CSS/HTML structure Commented May 23, 2017 at 13:12

3 Answers 3

2

Change:

#first {
    width: 200px;
    height: 200px;
    background-color: green;
    overflow: hidden;

}

To

#first {
width: 200px;
height: 200px;
background-color: green;

}

In other words, remove overflow: hidden and that blue div will appear as you wanted to.

Sign up to request clarification or add additional context in comments.

1 Comment

This should be a comment, not an answer.
0

Not entirely sure this is what you are after but all you need to do is change the overflow from hidden to visible on your first div:

#first {
    width: 200px;
    height: 200px;
    background-color: green;
    overflow: visible;  /* change this */
}

#second {
    width: 50px;
    height: 50px;
    background-color: red;
    position: relative;
}

#fourth
{
    width: 250px;
    height: 50px;
    background-color: blue;
    position: absolute;
    z-index: 100;
}
<div id="first">
    <div id="second">
      <div id="fourth">
      test
      </div>      
    </div>
</div>

1 Comment

This is not what I was fully intending as I was hoping to include the scrollbar still, but there seems to be no work around apart from moving the fourth div outside the first. So I am going to see if I can try positioning the element so it works out where the edge is of the containing div and displays within the containing div
0

As Wired said you have to remove the overflow: hidden; from the #first element. Otherwise all elements inside will be cut off if they should reach outside it's boundaries.

#first {
    width: 200px;
    height: 200px;
    background-color: green;
}

#second {
    width: 50px;
    height: 50px;
    background-color: red;
    position: relative;
}

#fourth
{
    width: 250px;
    height: 50px;
    background-color: blue;
    position: relative;
    top: 0;
    left: 0;
    z-index: 100;
}
<div id="first">
    <div id="second">
      <div id="fourth">
      test
      </div>      
    </div>
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.