0

I have created a simple demo of my problem.

.set-overflow{
  width: 300px;
  height: 300px;
  position: relative;
  overflow: auto;
}
.set-relative{
  overflow: hidden;
  width: 100%;
  height: 100%;
  background: blue;
}
.element{
  position: absolute;
  right: 0;
  bottom: -20px;
  background: yellow;
}
.set-overflow:hover .element{
  bottom: 0;
}
<div class="set-overflow">
  <div class="set-relative">
    <div class="element">content</div>
  </div>
</div>

I have two parents and element, which should appear on parent's hover. The problem is that I have to get rid of scroll without changing parents' properties.

Please note that it is just a simple example, so I have to solve this with minimum possible effect on the other elements. Thanks!

JSFiddle: https://jsfiddle.net/o0abLxek/15/

1
  • I didn't get that you want to use a transition on this element. Updated my answer, maybe it helps...? Commented Jul 11, 2018 at 15:21

2 Answers 2

2

make your child element to be height:0 on non-hover state:

.set-overflow{
  width: 300px;
  height: 300px;
  position: relative;
  overflow: auto;
}
.set-relative{
  overflow: hidden;
  width: 100%;
  height: 100%;
  background: blue;
}
.element{
  position: absolute;
  right: 0;
  bottom: 0;
  height:0;
  overflow:hidden;
  background: yellow;
}
.set-overflow:hover .element{
  height:auto;
}
<div class="set-overflow">
  <div class="set-relative">
    <div class="element">content</div>
  </div>
</div>

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

1 Comment

Sorry, I didn't mention that I want to use transition, so this solution is not what I need
1

Edited answer: Learning that you want to use a transition on the element (I'm guessing you want to make it slide up), I've updated my answer. height won't help you as you can't use transition on height, but you could use max-height instead, as pointed out in this question (How can I transition height: 0; to height: auto; using CSS?).

.set-overflow{
  width: 300px;
  height: 300px;
  position: relative;
  overflow: auto;
}
.set-relative{
  overflow: hidden;
  width: 100%;
  height: 100%;
  background: blue;
}
.element{
  position: absolute;
  right: 0;
  bottom: 0;
  max-height:0;
  overflow:hidden;
  background: yellow;
  transition: max-height 1s;
}
.set-overflow:hover .element{
  max-height:100px;
}
<div class="set-overflow">
  <div class="set-relative">
    <div class="element">content</div>
  </div>
</div>

Old answer: Instead of moving the element around on hover, why don't you use plain old visibility? Like so: https://jsfiddle.net/wpxehqkb/

1 Comment

Or display, that was my first thought as well. But maybe they want to add a transition to make it “move in” later on or sth. like that.

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.