Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a space between paragraphs when using css reset? [closed]

Tags:

html

css

What is the safest/no height change cross-browser way to add a space between paragraphs when using css reset?

<div>
<p class="text">paragraph1</p>
<p>&nbsp;</p>
<p class="text">paragraph2</p>
</div>
<div>
<p class="text">paragraph1</p>
<br>
<br>
<p class="text">paragraph2</p>
</div>

http://jsfiddle.net/unknown601/0ewvk3c9/

like image 335
Timothy Avatar asked Aug 11 '14 00:08

Timothy


People also ask

How do you put a space between paragraphs in CSS?

As in print layout programs, you can add space between paragraphs using margin-bottom or margin-top in your CSS, used below in the paragraph element. Compare the difference between the one without extra space (below, left) to the one with the added margin-bottom between paragraphs (below, right).

How do you add space between items in CSS?

To create space between list bullets and text in HTML, use CSS padding property. Left padding padding-left is to be added to <ul> tag list item i.e. <li> tag. Through this, padding gets added, which will create space between list bullets and text in HTML.

How do you add a blank space between paragraphs in HTML?

Creating extra spaces before or after text To create extra spaces before, after, or in-between your text, use the &nbsp; (non-breaking space) extended HTML character.


2 Answers

I find it useful to include space between adjacent paragraphs.

Example: http://jsfiddle.net/kppb0nLx/3/

/* a paragraph proceeded by another paragraph will have a top margin */
p + p {
    margin-top: 8px;
}

This allows you to keep paragraphs flush with the top/bottom of your container while still having space between them.

The options you listed (br and p purely for spacing) are not considered good practice. They don't represent the your content semantically and they create extra markup that can easily be replaced with CSS.

More Reading

like image 91
Tim M. Avatar answered Sep 30 '22 13:09

Tim M.


The <br> tag should only be used to break line i.e <p>This is first line <br> This is second line.</p>

For spacing i would have to say on based on my personal experience & on observation of most of the frameworks margin is the best practice to create spacing between paragraph.

DEMO

CSS:

p{
    margin: 0 0 10px;
}

Edit: I like @Tim Medora solution much better: p + p { margin-top: 8px; } by adding top margin to adjacent p tags we eliminate the first and last p tag margin issues commonly faced.

like image 20
Imran Bughio Avatar answered Sep 30 '22 13:09

Imran Bughio