I'm facing a issue, and trying to solve it using only CSS.
Here is my html
<body>
<p>empty</p>
<p><img src="/"></p>
<p><img src="/"></p>
<p>empty</p>
</body>
And my CSS
body {
counter-reset: my-sec-counter;
}
p {
position: relative;
}
p:after {
position: absolute;
font-size: 17px;
top: -15px;
right: -15px;
height: 40px;
width: 40px;
text-align: center;
line-height: 40px;
border-radius: 100px;
transition: .1s;
counter-increment: my-sec-counter;
content: "#" counter(my-sec-counter);
color: #fff;
border: 3px solid white;
background-color: black;
font-weight: bold;
}
But I'd like to display an after
element only if p
contains an img
. I tried img ~ p:after
but doesn't work.
Any help?
then p img:after will certainly work
– Keith Aug 27 '19 at 13:49