当一个div位于另一个div之上并且底部在悬停时滑出时如何设置较低的宽度?

发布于 2025-01-03 01:03:50 字数 798 浏览 2 评论 0原文

我有一个 div 放在另一个上面。悬停时,底部 div(右侧灰色条)滑出,并且与顶部 div 宽度相同: http:// /d.pr/OB6N。我正在尝试创建带有幻灯片的图像网格。有没有办法将宽度设置为图像中所示的宽度?因为现在,当我检查元素时,宽度是顶部 div 和滑出 div(完全滑出时)的总和。

 HTML:
    <div class="poster">
     <img src="example.png" />
    </div>
    <div class="bottombox"></div>

CSS:

.poster {
    float: left;
    width: 250px;
    height: 375px;
    display: inline-block;
    position: relative;
    left: 0px;
    z-index: 1;
    -webkit-transition-duration: 0.2s;
}

.bottombox {
    float: left;
    width: 250px;
    height: 375px;
    display: inline-block;
    position: relative;
    left: -225px;
    -webkit-transition-duration: 0.2s;
}

.bottombox:hover {
    left: 0px;
}

希望这是有道理的。谢谢!

I have one div on top of another. On hover, the bottom div (the right-side gray bar) slides out and is the same width as the top div: http://d.pr/OB6N. I'm trying to create a grid of images with slide-outs. Is there a way to set the width to be as much as is shown in the image? Because right now, when I inspect the element, the width is the total of the top div and the slide-out div (when fully slid out).

 HTML:
    <div class="poster">
     <img src="example.png" />
    </div>
    <div class="bottombox"></div>

CSS:

.poster {
    float: left;
    width: 250px;
    height: 375px;
    display: inline-block;
    position: relative;
    left: 0px;
    z-index: 1;
    -webkit-transition-duration: 0.2s;
}

.bottombox {
    float: left;
    width: 250px;
    height: 375px;
    display: inline-block;
    position: relative;
    left: -225px;
    -webkit-transition-duration: 0.2s;
}

.bottombox:hover {
    left: 0px;
}

Hope that makes sense. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一刻暧昧 2025-01-10 01:03:50

因此,如果您创建一个 jsfiddle 来玩,那么帮助您会更容易。也就是说,一种方法是使 .bottombox 成为 .poster 元素的子元素

<div class="poster">
  <img src="example.png" />
  <div class="bottombox"></div>
</div>

,然后将 .poster 的 css 更改为

width: auto

,将 .bottombox 的 css 更改为

width: 100%;
position: absolute;
left: 25px;

,最后将悬停定义设置为

left: 100%;

So it would be much easier to help you if you created a jsfiddle to play with. That said, one approach is to make .bottombox a child of the .poster element

<div class="poster">
  <img src="example.png" />
  <div class="bottombox"></div>
</div>

then change the css of .poster to

width: auto

and change the css of .bottombox to

width: 100%;
position: absolute;
left: 25px;

and last set the hover definition to

left: 100%;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文