Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding space between two attributes in a pseudo element content

Tags:

html

css

I have the following html

<div data-price="10" data-currency="USD"></div>

and I want to create a pseudo element that displays data in the attributes like this:

:before {
 content: attr(data-price) + ' ' + attr(data-currency)
}

My problem is that the space is not added between. Is there so special way to achieve it without harding the space in front in the attribute itself? Thank you.

like image 596
jacobdo Avatar asked Aug 24 '26 13:08

jacobdo


1 Answers

use content: attr(data-price) " " attr(data-currency); dont use + for concatenation

:before {
   content: attr(data-price) " " attr(data-currency);
}
  <div data-price="10" data-currency="USD"></div>
like image 92
Shiv Kumar Baghel Avatar answered Aug 27 '26 02:08

Shiv Kumar Baghel