html - CSS中如何将div向上移动以显示另一个div?

标签 html css

我有一个带有图像的 div (div_one)。在这个 div 下,我有另一个较小的 div (div_two)。 我想在悬停后,调整这个 div_one (带有图片)的大小(较小的高度)并显示这个 div_two,它位于图像下方。 但它并没有按照我想要的方式工作。图像跳转:/

.images {
  background: url('https://www.lokeshdhakar.com/projects/lightbox2/images/image-3.jpg');
  height: 200px;
  width: 150px;
  background-repeat: no-repeat;
  background-position: center;
  display: flex;
  align-items: flex-end;
}

.images:hover {
  height: 150px;
  width: 100px;
}

img {
  height: 200px;
  width: 150px;
}

.info {
  display: none --> I want this to show after hover
}
<div class="images">
  <div class="info">lorem ipsum</div>
</div>

有什么想法吗?

最佳答案

  1. 如果你想以更好的方式显示它,可以将其移到父元素之外。

  2. .images:hover + .info 将选择另一个元素。我更喜欢使用不透明度更改方式。

  3. 非悬停状态的transition属性将有助于演示,即图像不会跳转。

.images {
  background: url('https://www.lokeshdhakar.com/projects/lightbox2/images/image-3.jpg');
  height: 200px;
  width: 150px;
  background-repeat: no-repeat;
  background-position: center;
  display: flex;
  align-items: flex-end;
  transition: all ease 1s;
}

.images:hover {
  height: 150px;
  width: 100px;
}

img {
  height: 200px;
  width: 150px;
}

.info {
  opacity: 0;
  transition: all ease 1s;
}

.images:hover+.info {
  opacity: 1;
}
<div class="images">
</div>
<div class="info">lorem ipsum</div>

关于html - CSS中如何将div向上移动以显示另一个div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64467226/

相关文章:

python - BeautifulSoup - 如何获得美丽汤中的第二个下一个项目?

javascript - 创建相同 id 的多个实例

css - 如何仅使用 CSS 实现此布局?

php - onClick php PHP 函数然后重定向

html - css中的 "line box"是什么意思

html - 在响应式网页设计中重叠时裁剪图像

html - 如何在悬停时影响所有具有相同名称的类

css - SVG 线标记在 IE 中的缩放比例不同

css - (例如)p.post {color : #336;} and . post p {color : #336;}? 之间有什么区别

javascript - 如何在html中使用滚动条动态分配按钮?