CSS/SCSS rails 转换 div,但不是嵌套图像 (rails)

标签 css hover transform css-transforms

我正在尝试在主 div 中设置图像,将鼠标悬停在该 div 上将使附加图像按比例放大超过 2 秒。只有 div 本身(边框)缩放,而不是附加图像本身。在撰写本文时,尝试单独缩放图像没有任何作用。这是在 Rails 5.1.2 中完成的。我错过了什么?

views/community/index.html.erb:

<div class="scene">
    <div id="container1" class="image-div">
      <%= image_tag("hbehance.png", :id =>"first-image", :alt => "first symbol") %>
    </div>
</div>

样式表/community.css.scss:

.scene {
  position: relative;
  height: 35rem;
  margin: 1rem;
  width: 95%;
  left: 0;
  top: 0;
  background-image: asset_url("cityscape.jpeg");
  background-size: cover;
}

.image-div{
  position: absolute;
  bottom: 10%;
  width: 60px;
  height: 60px;
  border: 5px solid red;
}

img {
  position: absolute;
  width: 100%;
  transition: transform all 2s;
}

.image-div:hover {
  transform: scale(2);
}

最佳答案

想通了!

图像嵌套在 div 中,但需要附加以串联响应:

javascript/community.js:

document.addEventListener('DOMContentLoaded', function(){

  firstDiv = document.getElementById('container1');
  firstImage = document.getElementById('first-image');
  firstDiv.append(firstImage);

  function testJS(){
    firstDiv.style.left = "50%";
  }
  testJS();//tests that JS file connects properly when first setup
})

关于CSS/SCSS rails 转换 div,但不是嵌套图像 (rails),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46781866/

相关文章:

php - 无法样式化 Div

html - 将内容置于中心

javascript - 在 Raphael 中悬停时选择另一个路径对象

css - 悬停时的图标字体背景

php - 尝试使用 PHP 的 GD 库扭曲图像

javascript - JQuery 在 HTML 列表上动态使用鼠标悬停

css - 如何以 Bulma 方式垂直和水平居中某些内容?

c# - 如何将 SQL 转录为 LINQ

html - CSS 悬停效果不会在文本上触发

iPhone 纵向导航栏高度仍然较短