Skip to content Skip to sidebar Skip to footer

Html/css: How To Put Text Both Right And Left Aligned In A Paragraph

What would be the best code to have two bits of text in a single paragraph, one left aligned, the other right aligned, that also is: the least code as possible the easiest for cli

Solution 1:

Least amount of markup possible (you only need one span):

<p>This text is left. <span>This text is right.</span></p>

How you want to achieve the left/right styles is up to you, but I would recommend an external style on an ID or a class.

The full HTML:

<pclass="split-para">This text is left. <span>This text is right.</span></p>

And the CSS:

.split-para      { display:block;margin:10px;}
.split-paraspan { display:block;float:right;width:50%;margin-left:10px;}

Solution 2:

The only half-way proper way to do this is

<p><spanstyle="float: right">Text on the right</span><spanstyle="float: left">Text on the left</span></p>

however, this will get you into trouble if the text overflows. If you can, use divs (block level elements) and give them a fixed width.

A table (or a number of divs with the according display: table / table-row / table-cell properties) would in fact be the safest solution for this - it will be impossible to break, even if you have lots of difficult content.

Solution 3:

I wouldn't put it in the same <p>, since IMHO the two infos are semantically too different. If you must, I'd suggest this:

<pstyle="text-align:right"><spanstyle="float:left">I'll be on the left</span>
 I'll be on the right
</p>

Solution 4:

I have used this in the past:

html

January<spanclass="right">2014</span>

Css

.right {
    margin-left:100%;
}

Demonstration

Solution 5:

Ok what you probably want will be provide to you by result of:

  1. in CSS:

    div { column-count: 2; }

  2. in html:

    <div> some text, bla bla bla </div>

In CSS you make div to split your paragraph on to column, you can make them 3, 4...

If you want to have many differend paragraf like that, then put id or class in your div:

Post a Comment for "Html/css: How To Put Text Both Right And Left Aligned In A Paragraph"