How to align two text elements, one to the left and the other to the right, also on the same line. I'm aware it can be done using floats but I would like a float less solution. I'm looking for a way to do it using display:inline
.
HTML:
<div class="contailner">
<div class="inlineLeft">Item 1</div>
<div class="inlineRight">Item 2</div>
</div>
CSS:
.container {
width: 600px;
border: 1px solid blue;
}
.inlineLeft, .inlineRight {
display: inline;
}
.inlineRight {
...align right...
}
Make sure you set the text-align property for the first list item to "left" (ul li:first-child), and set the text-align property for the other list items (ul li) to "right". That aligns them to the left and to the right but on two suppurate lines.
You can use Flexbox instead and set margin-left: auto on inner div to move it to right.
To align things in the inline direction, use the properties which begin with justify- . Use justify-content to distribute space between grid tracks, and justify-items or justify-self to align items inside their grid area in the inline direction.
you could just use position:absolute
on the inline elements and position:relative
on the container. Then you can align the inline elements the way you want relative to the container. Something like this:
.container {
position: relative;
width: 600px;
border: 1px solid blue;
}
.inlineLeft, .inlineRight {
position: absolute;
display: inline;
}
.inlineRight {
right: 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With