[英]Using hidden overflow-x and visible overflow-y width absolute position without scroll
I've seen similar questions, have tried one, but this is not worked for my case. 我见过类似的问题,尝试过一个问题,但这不适用于我的情况。
Here is what I want: White and red rect is absolute position. 这就是我想要的:白色和红色矩形是绝对位置。 White triggered by hover on red.
白色悬停在红色上触发。 On this picture
overflow-x
is disabled. 在此图片上,
overflow-x
被禁用。
Because I need hide red rectangles outside the blue box, I added overflow-x: hidden
, and it causes y scroll when hovered red rect. 因为我需要在蓝色框外隐藏红色矩形,所以我添加了
overflow-x: hidden
,并且将鼠标悬停在红色矩形上时会导致y滚动。 Like this: 像这样:
.container { width: 210px; } .grid { position: relative; overflow-x: hidden; width: 100%; height: 210px; background: #333344; } .grid__item { position: absolute; height: 200px; width: 200px; background: #994444; } .grid__item .grid__item-hover { display: none; position: absolute; bottom: -50px; height: 50px; width: 100%; background-color: white; } .grid__item:hover .grid__item-hover { display: block; } .grid__item:nth-child(1) { left: 5px; top: 5px; } .grid__item:nth-child(2) { left: 210px; top: 5px; } .bar { height: 100px; background: #aaaaaa; }
<div class="container"> <div class="grid"> <div class="grid__item"> <div class="grid__item-hover"></div> </div> <div class="grid__item"> <div class="grid__item-hover"></div> </div> </div> <div class="bar"></div> </div>
Need solution without javascript. 需要没有JavaScript的解决方案。
Is it because your .grid width is greater than your container width? 是否因为您的.grid宽度大于容器宽度? ie
即
container {
width: 210px;
}
.grid {
width: 100%;
}
I am saying .grid width of 100% is greater than container width of 210px, therefore the scroll bar is appearing. 我是说100%的.grid宽度大于210px的容器宽度,因此出现了滚动条。 Try making the container width greater than the grid width.
尝试使容器宽度大于网格宽度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.