Absolute positioned element is getting cut off (hidden) from only top

41 Views Asked by At

I have a div with className recent-files-container that has a div with className="box"

the box is relative and it has an absolute positioned div with class = "x-btn". I want to show this x-btn at the top right corner of the box with negative top and right values so it can be positioned a little bit offside/outside the box. The problem is the x-btn is getting clipped/hidden from the top side only

enter image description here

<div className="recent-files-container">
  <div className="box">
     <div
        className="drag-box"
        ref={drag}
        style={{
          border: isDragging ? "3px solid #8b3dff" : "0px",
          opacity: isDragging ? 0.5 : 1,
          cursor: "grab",
        }}
      >
        <img src={file.data} alt={file.name} />
       
      </div>
       <div className="x-btn">
          X
        </div>
  </div>
</div>

.content .recent-files-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-wrap: wrap;
  overflow: auto;
  margin-top: 15px;
}

When I am commenting the overflow: auto in the recent-files-container the absolute positioned x-btn is no longer hidden but I need overflow auto because recent-files-container will have the dynamic number of divs with className box. So, it needs the overflow auto

enter image description here

The remaining CSS is below

.recent-files-container .box {
  background-color: #353738;
  width: calc(33.33% - 10px);
  height: 110px;
  margin-right: 10px;
  margin-bottom: 10px;
  position: relative;
}

.box .drag-box {
  width: 100%;
  height: 100%;
}

.box .drag-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.box .x-btn {
  position: absolute;
  top: -10px;
  right: -10px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #8b3dff;
  color: #fff;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  border: none;
  outline: none;
  cursor: pointer;
}
0

There are 0 best solutions below