I used ::before or ::after to insert a picture. The code in CSS is like this:
p::before {
content: url(../image/xs.jpg);
}
or
p::after {
content: url(../image/submit.png);
}
When I inspect the width of ::before or ::after, the width of the content-box is the same with the width of the picture. However, the height of the content-box is automatically set and is lower than the height of the picture. I tried to specify the height like this:
p::before {
height: 37px;
}
or
p::before {
height: 71px;
}
It does not work. Neither does overflow. Is there any way to specify the height in this situation?
From the specification you can read:
So the image will be inside the pseudo element and applying width/height will simply control the pseudo element not the image.
Here is an example to illustrate:
Notice how the text is aligned respecting the baseline alignment relatively to the image. It's exacly the same as doing the following:
So technically we cannot control the height/width of the image since we have no way to select it (maybe in the future we will)
The only solution is to consider it as background so it's a part of the pseudo element: