Home >Web Front-end >CSS Tutorial >Can CSS Data Attributes Render Newline Characters with Pseudo-Elements?
Can you incorporate newline characters within CSS data attributes, allowing them to be displayed using pseudo-elements? Let's explore this scenario.
Consider the following CSS and HTML code:
[data-foo]:after { content: attr(data-foo); background-color: black; }
<div data-foo="First line \a Second Line">foo</div>
In this scenario, the "a" character, expected to be a newline character in CSS, fails to produce the desired result.
Solution:
To achieve the desired behavior, modify the data attribute as follows:
<div data-foo="First line 
 Second Line">foo</div>
Explanation:
The above is the detailed content of Can CSS Data Attributes Render Newline Characters with Pseudo-Elements?. For more information, please follow other related articles on the PHP Chinese website!