是可控制的::: before或:: after插入的图片的高度吗?

问题描述 投票:0回答:1

我使用:: before或:: after插入图片。 CSS中的代码如下:

p::before {
    content: url(../image/xs.jpg);
}

p::after {
    content: url(../image/submit.png);
}

[当我检查:: before或:: after的宽度时,内容框的宽度与图片的宽度相同。但是,内容框的高度是自动设置的,并且低于图片的高度。我试图像这样指定高度:

p::before {
    height: 37px;
}

p::before {
    height: 71px;
}

它不起作用。都不会溢出。在这种情况下,有什么方法可以指定高度吗?

css pseudo-element
1个回答
0
投票

使用背景图像

.image:before {
  content:"";
  display:block;
  background-image: url(https://via.placeholder.com/150);
  height: 150px;
  width: 150px;
}

https://jsfiddle.net/3nmroeLu/

© www.soinside.com 2019 - 2024. All rights reserved.