如何用图标覆盖图像

时间:2015-07-09 10:28:23

标签: css image icons pseudo-element

以下是https://jsbin.com/rekaxa/edit?html,css,output示例。 我想把红色圆圈(图标)放在图像上,但要保持html直截了当。实施它的最佳方式(可能完全不同)是什么?

1 个答案:

答案 0 :(得分:1)

你还没有说过你想要图标的位置,所以我选择了div的死角。



div {
  background-color: green;
  width: 280px;
  height: 180px;
  position: relative;
}
img {
  margin: 0 auto;
  display: block;
}
div:after {
  content: '';
  position: absolute;
  top: 50%; /* adjust as requiured */
  left: 50%; /* adjust as required */
  margin-top: -15px;
  margin-left: -15px;
  width: 30px;
  height: 30px;
  background: red;
  display: block;
  border-radius: 15px;
}

<div class="icon">
  <img src="http://dummyimage.com/200x150/000/fff" />
</div>
&#13;
&#13;
&#13;