首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将元素绑定到背景图像(响应式)?

如何将元素绑定到背景图像(响应式)?
EN

Stack Overflow用户
提问于 2016-05-30 17:58:00
回答 1查看 71关注 0票数 0

是否可以将(HTML)元素绑定到父元素的背景图像?在下面的示例代码中,我希望(悬停)元素始终留在块上,即使窗口调整为小(移动)大小的屏幕也是如此。

代码语言:javascript
复制
.steps {
  background: url(https://i.gyazo.com/c027c7cefa8f66fb10135547ac650d24.png) center no-repeat;
  background-size: contain;
  height: 95px;
}
.steps ul {
  /* margin-top: 0; */
  /* margin-left: -246px; */
  margin-left: -286px;
  left: 50%;
  top: 0%;
  margin-top: 13px;
  position: absolute;
}
.steps ul li {
  display: inline-block;
  margin: 0 2px;
}
.steps ul li a {
  display: block;
  height: 82px;
  width: 116px;
  /*margin-bottom: 22px;*/
  text-indent: -9999em;
}
.steps ul li a:hover {
  background: rgba(255, 255, 255, 0.25);
}
代码语言:javascript
复制
<div class="steps">
  <ul class="list-unstyled">
    <li>
      <a href="#">Block 1</a>
    </li>
    <li>
      <a href="#">Block 2</a>
    </li>
    <li>
      <a href="#">Block 3</a>
    </li>
    <li>
      <a href="#">Block 4</a>
    </li>
  </ul>
</div>

JSFiddle

现在出现的问题是,这些块不会保持在队列中。我想在这周围放置一个父容器元素,但这将导致图像不再居中。

有人能在这方面给我一些建议吗?

EN

回答 1

Stack Overflow用户

发布于 2016-05-30 18:21:09

我注意到你在使用:

位置:绝对;

绝对定位不是一种适合响应式设计的技术。对于响应式设计,通常会使用相对大小单位,如ems,并使用相对定位技术而不是绝对定位技术。我想说,你需要重新考虑你的设计技巧,使用相对大小和相对位置。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37522749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档