Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you add line breaks to the :after pseudo element?

I want to append a <br /> to a particular class. Using the :after pseudo class simply displays <br /> as text.

Is there a way to make this work?

It's internal for IE8 so browser issues aren't a problem. If I do

<span class="linebreakclass">cats are</span> brilliant 

I want "brilliant" to appear on a new line.

like image 955
NibblyPig Avatar asked Nov 04 '09 10:11

NibblyPig


People also ask

How do you apply additional line breaks after each tag?

To add a line break to your HTML code, you use the <br> tag. The <br> tag does not have an end tag. You can also add additional lines between paragraphs by using the <br> tags. Each <br> tag you enter creates another blank line.

Which tag is used to insert line break after an element?

The <br> HTML element produces a line break in text (carriage-return).

Is after a pseudo element?

::after (:after) In CSS, ::after creates a pseudo-element that is the last child of the selected element. It is often used to add cosmetic content to an element with the content property. It is inline by default.


2 Answers

You won't be able to render HTML tags but you can set style like this:

.needs-space:after {     content: " ";     display: block;     clear: both; /* if you need to break floating elements */ } 

The main setting here is display: block; This will render :after content inside a DIV. And this pseudo element is supported by all latest browsers. Including IE. Saying this you should be aware of your users and their browsers.

like image 198
Robert Koritnik Avatar answered Sep 21 '22 02:09

Robert Koritnik


You can use \A escape sequence, which will render as a newline:

.new-line:after {   white-space: pre-wrap;   content: "\A"; } 

This method was mentioned in the CCS 2.1 Specification for the content property:

Authors may include newlines in the generated content by writing the "\A" escape sequence in one of the strings after the 'content' property. This inserted line break is still subject to the 'white-space' property.

like image 45
Dmitry Schetnikovich Avatar answered Sep 21 '22 02:09

Dmitry Schetnikovich