溢出绝对元素在网格项目中不可见



我有1 x 6网格。我想在悬停网格项目时显示调整大小的句柄。为此,我有2个圆形的绝对位于网格项目中的div。我放在项目两侧边缘的中间。我希望将这些两个手柄放置在梁项目边缘外的一半半范围内。这是代码段。我需要该溢出:网格项目的自动,以防止网格项目扩展以适应其内容。

预先感谢。

.wrapper{
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-auto-rows: 150px;
  grid-gap: 10px;
}
.item{
  position: relative;
  background: lightyellow;
  border: 2px dashed transparent;
  overflow: auto;
}
.item:hover{
  border-color: #333;
  padding: 10px;
}
.round{
  position: absolute;
  height: 15px;
  width: 15px;
  border-radius: 50px;
  border: 1px solid #333;
  top: calc(50% - 7.5px);
  background: lightgreen;
}
.round:nth-child(1) {
    left: -7.5px !important;
}
.round:nth-child(2){
  right: -7.5px;
}
<div class="wrapper">
  <div class="item span2">
    <div class="round"></div>
    <div class="round"></div>
    <p>This is the text of the box. This box will grow to fit the content if i remove the overflow. But i dont want this behaviour. So i am setting overflow to auto. But i want that two rounded green box to fit on half inside and half outside of box. Now it is another half is not visible. </p>
  </div>
  <div class="item"></div>
  <div class="item"></div>
</div>

您可以使用固定位置使用null变换技巧:

.wrapper{
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-auto-rows: 150px;
  grid-gap: 10px;
  transform:translate(0,0);
}
.item{
  position: relative;
  background: lightyellow;
  border: 2px dashed transparent;
  overflow: auto;
}
.item:hover{
  border-color: #333;
  padding: 10px;
}
.round{
  position: fixed;
  height: 15px;
  width: 15px;
  border-radius: 50px;
  border: 1px solid #333;
  top: calc(50% - 7.5px);
  background: lightgreen;
}
.round:nth-child(1) {
    left: -7.5px !important;
}
.round:nth-child(2){
  left: calc((100% / 6) - 17.5px);
}
<div class="wrapper">
  <div class="item span2">
    <div class="round"></div>
    <div class="round"></div>
    <p>This is the text of the box. This box will grow to fit the content if i remove the overflow. But i dont want this behaviour. So i am setting overflow to auto. But i want that two rounded green box to fit on half inside and half outside of box. Now it is another half is not visible. </p>
  </div>
  <div class="item"></div>
  <div class="item"></div>
</div>

最新更新