twitter-bootstrap - 如何将图像设置在另一个图像之上?

标签 twitter-bootstrap css

enter image description here

图片应该对所有设备都有响应。 我用过

    <img src="images/enter/red20.png" class=" img-responsive" 
        style="max-width:15%;position: absolute; right: 30%;"/>
    <img src="images/enter/computer.png" class=" img-responsive" />

在第一个顶部图像上,但何时更改大小或浏览器顶部图像移动到其他位置。请参阅上面链接中的设计。

最佳答案

关键是结合最大宽度使用百分比。

大图,你给它一个 max-width: 100%,因此它永远不会比它自己的尺寸大,但也不会比它的父级大。

将该图像包裹在父 div 中。这个 div 变成了一个 display: inline-block,所以我的宽度和它的内容一样。你把这个 div 放在相对位置。

然后我们将小图像添加到 div 中并将其放置在绝对位置。它的位置将相对于父级 (div) 而不是主体。给它一个 25% 的最大宽度(例如),并以 % 为单位给它一个顶部和左/右位置。

HTML:

<div class="wrapper">
  <img class="big-img" src="big.png" />
  <img class="small-img" src="big.png" />
</div>

CSS:

.wrapper{
  display: inline-block;
  position:relative;
}
.big-img{
  width: 100%;
  max-width: 100%;
  border: 1px solid blue;
}
.small-img{
  border: 1px solid red;
  position:absolute;
  right: 10%;
  top: 10%;
  width: 25%;
  max-width:25%;
}

DEMO

缩小结果窗口,您将看到图像调整大小。

关于twitter-bootstrap - 如何将图像设置在另一个图像之上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37319212/

相关文章:

jquery - Bootstrap 选项卡式内容未正确隐藏

Jquery - 滑动菜单(手工制作)

javascript - Safari HTML 5 视频无法播放

html - 为什么我的 h2 不在一行?

javascript - 我必须使用脚本、html、css 更改类

jquery - Bootstrap Navbar 展开后不折叠

html - 图像未与 Bootstrap 行的中心对齐

css - 带有响应式 CSS 掩码的 Bootstrap

html - 如何居中 Bootstrap 导航栏,但也拉 1 个元素吗?

css - 如何在没有 Javascript 的情况下居中包裹 float