Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to right align a <p> tag?

Tags:

html

css

I have a couple of <p> tags that I want to right align. Does anyone know how to do this?

like image 355
Xaisoft Avatar asked Jan 06 '09 19:01

Xaisoft


2 Answers

CSS:

p {
    text-align: right;
}

INLINE:

<p style="text-align: right">Some Text</p>

jQuery:

$('p').css('text-align', 'right');

Javascript:

var aElements = document.getElementsByTagName('p');
for (var i = 0; i < aElements.length; i++) {
    aElements[i].style.textAlign = 'right';
}
like image 131
enobrev Avatar answered Nov 13 '22 06:11

enobrev


It depends. Do you want the entire paragraph to align to the right side of whatever container it's in? Or do you want the text of the paragraph to align to the right margin of the paragraph?

If it's the first, look into the float: right; CSS directive. The latter, text-align: right;

like image 8
foxxtrot Avatar answered Nov 13 '22 06:11

foxxtrot