I feel like I saw a way, using the CSS content property, to insert a line break tag before an element. Obviously this doesn't work: Show
But how do you do this?
syb0rg 7,9878 gold badges40 silver badges80 bronze badges asked Sep 9, 2011 at 15:12
3 It's possible using the
You may also need to add note: p.s. Another treatment to be
Nam G VU 31.6k67 gold badges221 silver badges356 bronze badges answered Aug 1, 2012 at 0:33
bookcaseybookcasey 38k13 gold badges74 silver badges93 bronze badges 5 If
This will have the effect of ensuring a line break both before and after the element. There is not a way to have CSS insert something that acts like a line break only before an element and not after. You could perhaps cause
a line-break before as a side-effect of other changes, for example answered Sep 9, 2011 at 15:21
bobincebobince 519k102 gold badges646 silver badges825 bronze badges 3 This works for me:
answered Nov 7, 2013 at 18:49
hutornyhutorny 85311 silver badges16 bronze badges 2 Following CSS worked for me:
answered Oct 7, 2017 at 13:49
rluksrluks 2,6227 gold badges35 silver badges53 bronze badges 2
There are two reasons why you cannot add generated content via CSS in the way you want:
There is an Best bet is use a bit of jQuery here:
Example: http://jsfiddle.net/jasongennaro/sJGH9/1/ answered Sep 9, 2011 at 15:39
Jason GennaroJason Gennaro 34.1k7 gold badges62 silver badges86 bronze badges 1 Just put a unicode newline character within the before pseudo element:
Andy 3,3462 gold badges22 silver badges44 bronze badges answered Apr 19, 2013 at 5:06
Jesse KinsmanJesse Kinsman 7121 gold badge7 silver badges20 bronze badges 1 Yes, totally doable but it is definitely a total hack (people may give you dirty looks for writing such code). Here is the HTML:
Here is the CSS:
Here is the fiddle: http://jsfiddle.net/AprNY/ answered Apr 18, 2013 at 21:13
mw1mw1 1,4821 gold badge11 silver badges18 bronze badges 2 Try the following:
Fizzix 22.8k37 gold badges109 silver badges170 bronze badges answered Dec 3, 2014 at 22:56
useruser 20.9k9 gold badges110 silver badges98 bronze badges 1 You can populate your document with
answered Nov 27, 2017 at 14:39
JackHammerJackHammer 4181 gold badge3 silver badges15 bronze badges assuming you want the line height to be 20 px
answered Mar 10, 2016 at 12:33
KareemKareem 4,65540 silver badges35 bronze badges I had no luck at all with inserting a break with :before. My solution was to add a span with a class and put the break inside the span. Then change the class to display: none; or display: block as needed. HTML
CSS
Hope this helps. answered Jun 7, 2016 at 14:37
RogerRoger 1212 silver badges12 bronze badges You can also use the pre-encoded HTML entity for a line break answered Jul 6, 2016 at 9:55
Henry GibsonHenry Gibson 1,9682 gold badges14 silver badges12 bronze badges
https://www.w3.org/TR/CSS2/generate.html#x18 The Content Proerty, "newlines"... p will not add margin nor padding at end of p inside parent block (e.g., body › section › p). "\A " line break forces line space, equivalent styled line-height. answered Jun 14, 2019 at 18:32
Instead of manually adding a line break somehow, you can do implement answered Oct 2, 2013 at 21:16
andy4thehuynhandy4thehuynh 1,9623 gold badges26 silver badges37 bronze badges 1 Add a answered Sep 9, 2011 at 15:15
4 How do you add a br tag in CSS?How to add a line-break using CSS. Set the content property to "\a" (the new-line character).. Set the white-space property to pre . This way, the browser will read every white-space, in myClass , as a white-space.. Can you style a BR in CSS?Styling with CSS
The <br> element has a single, well-defined purpose — to create a line break in a block of text. As such, it has no dimensions or visual output of its own, and there is very little you can do to style it.
How do you type a BR tag?In HTML, a line break is made with the <br> tag. We don't need to close <br> because it's an empty tag. To break a line, either <br/> or <br></br> are acceptable.
What does BR mean in CSS?Definition and Usage
The <br> tag inserts a single line break. The <br> tag is useful for writing addresses or poems.
|