文本在图像上的绝对位置

Dav*_*vid 0 html css css-position

我有一个图像,我需要在右下角添加一个标签.

当我把它推到那里时,它比图像低4px,没有填充也没有边距.

.postImage {
    position: relative;
    display: inline-block;
}
.post img.thumbnail {
    width:100%;
    height: 100%;
}
.commercial {
    position: absolute;
    bottom: 0;
    right: 0;
    background-color: #666;
    color: #fff;
    padding: 3px;
    font-size: 14px;
    font-weight: 100;
}
Run Code Online (Sandbox Code Playgroud)
<div class="postImage">
  <img class="thumbnail" src="https://dummyimage.com/600x400/f00/fff">
  <span class="commercial">commercial</span>
</div>
Run Code Online (Sandbox Code Playgroud)

修复它的最佳方法是什么?我不认为

bottom: 4px;
Run Code Online (Sandbox Code Playgroud)

是正确的.

谢谢

Sup*_*ser 5

默认情况下,图像标记在底部占用一些额外的空间,因为它是内联元素.将其更改为block元素以删除额外的空间

.thumbnail {
    display: block; /*inline-block, float:left etc..*/
}
Run Code Online (Sandbox Code Playgroud)

.postImage {
    position: relative;
    display: inline-block;
}
.post img.thumbnail {
    width:100%;
    height: 100%;
}
.commercial {
    position: absolute;
    bottom: 0;
    right: 0;
    background-color: #666;
    color: #fff;
    padding: 3px;
    font-size: 14px;
    font-weight: 100;
}
.thumbnail {
    display: block;
}
Run Code Online (Sandbox Code Playgroud)
<div class="postImage">
  <img class="thumbnail" src="https://dummyimage.com/600x400/f00/fff">
  <span class="commercial">commercial</span>
</div>
Run Code Online (Sandbox Code Playgroud)