Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I simulate <br/> (the br tag) using CSS?

Tags:

html

css

I have the following line of css and html here:

CSS:

.top, .title {
font-weight: bold;
}
.bottom, .Content {
}

HTML:

<span class='title'>Title</span>
<br/>
<span class='Content'>Content</span>
<br/><br/>

I would like to replace the <br/> tag with an equivalent in CSS, but I am struggling with it. I would appreciate any help.

I've tried margin-bottom, margin-top, line-height, none of it worked.

like image 991
user717236 Avatar asked Feb 07 '12 22:02

user717236


People also ask

What can I use instead of Br in CSS?

There are many ways to break the line without using <br> tag. The used properties are listed below: white-space: pre; It is used to make elements acts like <pre> tag. display: block; It sets the display property of elements to block.

What is the CSS for BR tag?

Styling with CSS The <br> element has a single, well-defined purpose — to create a line break in a block of text.

How do I customize my br tag?

There is a way by which you can increase line break between lines, is by putting multiple br tags. Method-1: Use various span classes with a different style applied to them, you can change the value of “margin-bottom” for these classes to change the height of line break.


2 Answers

You can simulate BR tags width CSS like this:

span:after {
    content: ' ';
    display: block;
}

Use the selector ":before" if you need the "br" been simulated before the span content

jsfiddle

like image 103
Viter Rod Avatar answered Oct 03 '22 20:10

Viter Rod


<span> is an inline element, so can't have margin applied, but it can take padding - give it something like .title { padding: 10px 0; } and it'll simulate a paragraph, or just .title { display: block; } to force the next thing to go beneath it.

like image 43
Joe Avatar answered Oct 03 '22 22:10

Joe