Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS how to align one word left and another word right within the same div?

Tags:

css

How to align one word left and another word right within the same div?

like image 688
Jigs Avatar asked May 26 '10 16:05

Jigs


People also ask

How do you align words on the same line in CSS?

The text-align-last property specifies how to align the last line of a text. Notice that the text-align-last property sets the alignment for all last lines within the selected element. So, if you have a <div> with three paragraphs in it, text-align-last will apply to the last line of EACH of the paragraphs.

How do I align two elements on the same line in CSS?

To get all elements to appear on one line the easiest way is to: Set white-space property to nowrap on a parent element; Have display: inline-block set on all child elements.


1 Answers

Solution 1:

HTML:

<div>
    <div class="left">left text</div>
    <div class="right">right text</div>
</div>

CSS:

.left {
    float: left;
}
.right {
    float: right;
}

Solution 2:

HTML:

<div>
    <div class="left">left text</div><!-- no space here
 --><div class="right">right text</div>
</div>

CSS:

.left {
    text-align: left;
}
.right {
    text-align: right;
}
.left, .right {
    display: inline-block;
    width: 50%;
}
like image 172
Eric Avatar answered Sep 22 '22 14:09

Eric