我有一个响应式/高度图像,我想将绝对元素逐个放置到img中,但是我不知道该怎么做,因为图像大小是动态的。

码:



#contenedorimagen {
  width: 100%;
  background: #000;
}
#imagen {
  position: relative;
  width: 100vw;
  height: 90vh;
  vertical-align: middle;
  text-align: center;
}
#i {
  max-width: 100%;
  height: auto;
  max-height: 100%;
}
#imagen #c {
  position: absolute;
  top: 0;
  left: 0;
  color: #fff;
}
#imagen #h {
  position: absolute;
  top: 0;
  right: 0;
  color: #fff;
}
#imagen #pm {
  position: absolute;
  bottom: 0;
  left: 0;
  color: #fff;
}

<div id="contenedorimagen">
  <div id="imagen">
    <div id="c">0</div>
    <div id="h">0</div>
    <div id="pm">0</div>
    <img id="i" src="https://i.imgur.com/kLkrgKO.jpg" />
  </div>
</div>





谢谢

范例图片
firefox

最佳答案

您需要给图像容器max-width



#contenedorimagen {
    width: 100%;
    background: #000;
}

#imagen {
    position: relative;
    width: 100vw;
    height: 90vh;
    max-width: 100%;
    vertical-align: middle;
    text-align: center;
}

#i {
    max-width: 100%;
    height: auto;
    max-height: 100%;
}

#imagen #c {
    position: absolute;
    top: 0;
    left: 0;
    color: #fff;
}

#imagen #h {
    position: absolute;
    top: 0;
    right: 0;
    color: #fff;
}

#imagen #pm {
    position: absolute;
    bottom: 0;
    left: 0;
    color: #fff;
}

<div id="contenedorimagen">
    <div id="imagen">
        <div id="c">0</div>
        <div id="h">0</div>
        <div id="pm">0</div>
        <img id="i" src="https://i.imgur.com/kLkrgKO.jpg" />
    </div>
</div>

09-07 18:36