html - 位置相对div内的绝对?

标签 html css position

基本上我有两张图片,一张没有灯,一张有灯,当用户将鼠标悬停在图片上时,它会打开灯。

我试图将灯定位到具有绝对位置的特定位置,这很好,但每当我缩放页面时它都会改变位置,现在我知道这是因为它超出了页面的流动范围所以我阅读了相关内容topics 将其放在具有相对位置的 div 中,我已经这样做了,但它仍然不起作用。

#cont {
  position: relative;
  height: 100%;
}
#cont a {
  position: absolute;
  bottom: 69px;
  left: 350px;
}
.foo img:last-child {
  display: none
}
.foo:hover img:first-child {
  display: none
}
.foo:hover img:last-child {
  display: inline-block
}
<section class="flexheader">
  <img class="logo" alt="" src="image/logo.png">
  <img class="house" alt="" src="image/house.png">
  <div id="cont">
    <a class="foo" href="#">
      <img alt="" src="image/lampnolight.png">
      <img alt="" src="image/lamp.png">
    </a>
  </div>
</section>

最佳答案

您需要使用它来使缩放工作完美:

.flexheader,
body, html {
  height: 100%;
  margin: 0;
  padding: 0;
}

片段

.flexheader,
body, html {
  height: 100%;
  margin: 0;
  padding: 0;
}
#cont {
  position: relative;
  height: 100%;
}
#cont a {
  position: absolute;
  bottom: 69px;
  left: 350px;
}
.foo img:last-child {
  display: none;
}
.foo:hover img:first-child {
  display: none;
}
.foo:hover img:last-child {
  display: inline-block;
}
<section class="flexheader">
  <img class="logo" alt="" src="//placehold.it/100?text=logo" />
  <img class="house" alt="" src="//placehold.it/100?text=house" />
  <div id="cont">
    <a class="foo" href="#">
      <img alt="" src="//placehold.it/100?text=lampnolight" />
      <img alt="" src="//placehold.it/100/ccf?text=lamp" />
    </a>
  </div>
</section>

关于html - 位置相对div内的绝对?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41411956/

相关文章:

javascript - 无法自动播放隐藏在自定义缩略图后面的 Youtube 视频

javascript - 如何始终在 slotmachine jquery 上显示 3 位数

html - "apple-touch-icon-precomposed"不是 rel 属性的真实值?

javascript - 如何使 slider 响应?

css - 如何在子主题中格式化预加载 header 请求

javascript - 始终在列表中选择一个 <li>

html - 将绝对 div 放置在相对 div 旁边

javascript - 为什么存在以及如何从页面 [Img inside] 中删除此空白区域

javascript - 创建移动的文本装饰

css - Position Fixed with Position Relative 位置固定