Why Overflow problem with absolute position

60 Views Asked by At

I want a sidebar with items that when hovered, it show subs items. I got a problem with overflow and absolute position, pls help me. Thanks! The detail in this video: https://youtu.be/4D3hNu2JBvU

Here is the code:

https://play.tailwindcss.com/Go8GAXt5AP

https://jsfiddle.net/coder039/qaz4dp9o/18/

overflow-y: auto;

Thanks!

Hi! I want a sidebar with items that when hovered, it show subs items. I got a problem with overflow and absolute position, pls help me. Thanks!

1

There are 1 best solutions below

3
Yuvaraj M On

overflow-y due to the position left use top instead and I applied the best case to show the side bar when hover.

*,
*::before,
*::after {
  box-sizing: border-box;
}

body,
html {
  margin: 0;
  padding: 0;
}

.parent {
  display: grid;
  height: 100vh;
  grid-template-columns: 150px 1fr;
}

.sidebar {
  display: flex;
  flex-direction: column;
  border: 1px solid #ddd;
}

.content {
  border: 1px solid #ddd;
}

.item {
  margin-bottom: 8px;
  display: flex;
  width: 100%;
  height: 50px;
  flex-shrink: 0;
  justify-content: center;
  align-items: center;
  background: rgb(253, 230, 138);
}

.item.item-with-subitems {
  position: relative;
}
.item.item-with-subitems > span{
  cursor:pointer;
}
.subitems-container {;
  position: absolute;
  right: -70%;
  width: 100px;
  background: #ff0000;
  opacity: 0;
  display:none;
  transform:scale(0.99) translateY(-0.7em);
  transform-origin:top;
  transition-timing-function:cubic-bezier(0.16, 1, 0.3, 1);
  transition-duration:500ms;
  transition-property:opacity,transform;
  list-style: none;
  padding: .5rem;
}

.item.item-with-subitems:hover > .subitems-container {
  opacity: 1;
  transform: scale(1) translateY(0);
  display:block;
}
<div class="parent">
  <div class="sidebar">
    <div class="item">home</div>
    <div class="item item-with-subitems">
      <span>code</span>
      <ul class="subitems-container">
        <li><a href="#">javascript</a></li>
        <li><a href="#">scheme</a></li>
        <li><a href="#">clojure</a></li>
        <li><a href="#">golang</a></li>
      </ul>
    </div>
    <div class="item">news</div>
    <div class="item">c</div>
    <div class="item item-with-subitems">
      <span>sport</span>
      <ul class="subitems-container">
        <li><a href="#">soccer</a></li>
        <li><a href="#">badminton</a></li>
        <li><a href="#">swimming</a></li>
      </ul>
    </div>
    <div class="item">c</div>
    <div class="item">c</div>
    <div class="item">c</div>
    <div class="item">c</div>
    <div class="item">c</div>
    <div class="item">c</div>
    <div class="item">c</div>
  </div>
  <div class="content">content</div>
</div>