1

I have the following code, it is a <div> element which contains two <span> elements separated by a <br>

<div style="background-color: orange;">
    <span>Foo</span><br>
    <span>Bar</span>
</div>

https://jsfiddle.net/73bwrdxk/

Not sure if relevant but I am using Bootstrap 3.

I would like that the second <span> (the one with the text Bar) will be right aligned.

M.E.
  • 4,955
  • 4
  • 49
  • 128

5 Answers5

4

you can use float

style="float: right;"

Using In-line style tag

<div style="background-color: orange;">
    <span>Foo</span>
    <br>
    <span style="float: right;">Bar</span>
</div>

Using bootstrap (pull-left and pull-right)

<div style="background-color: orange;">
    <span>Foo</span>
    <br>
    <span class="pull-right">Bar</span>
</div>

DEMO (Using In-line style tag)

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
2

use bootstrap class pull-right in span to make its align right

<div style="background-color: orange;">
    <span>Foo</span><br>
    <span class="pull-right">Bar</span>
</div>
Hasanuzzaman Sattar
  • 592
  • 1
  • 5
  • 20
2

.spanl{
float:right;

}
<div style="background-color: orange;" class=" ">
<span>Foo</span>
<span class="spanl">Bar</span>
</div>
Hp_issei
  • 579
  • 6
  • 18
2

You can simply replace with this code:

<div style="background-color: orange;">
    <span>Foo</span><br>
    <span style="float:right">Bar</span> 
</div>
R Hazarika
  • 21
  • 3
  • Welcome to Stackoverflow. It would be better if you checkout [How to Answer](https://stackoverflow.com/help/how-to-answer) page for future endeavor at Stack overflow. -Thank you – Momin Mar 10 '18 at 03:36
1

You ca make use of float property and clearfix. Using Float on child Elements collapse the parent element size. So you need to add clearfix class to parent to avoid collapse situation.

.clearfix::after{
    content:"";
    display:table;
}

.floatRight{
  float:right;
}
<div style="background-color: orange;" class="clearfix">
<span>Foo</span>
<span class="floatRight">Bar</span>
</div>
Chandra Shekhar
  • 3,550
  • 2
  • 14
  • 22