Is it possible in CSS to set an element's ::before
content to a url passed as a data-attribute?
For example, if I have a bunch of testimonials and testimonial "headshots", I'm trying to pass them to CSS like so:
PHP / HTML:
$image_src = wp_get_attachment_image_src($image)[0];
echo '
<div class="testimonial fp-card content-section content-section--has-center-image" data-image="' . $image_src . '">
<div class="testimonial__text">' . $text . '</div>
</div>';
SCSS:
.testimonial {
&::before {
content: attr(data-image); // This outputs the string URL. How can I use the string URL as an actual URL?
position: absolute;
top: -0.5rem;
right: 50%;
transform: translateX(-50%);
// Etc
}
}
Is there a way to pass the url from the data-image
attribute to the ::before
content as a valid URL?
I tried content: url(attr(data-image))
, but that didn't work.