Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I align two span elements one to the left, the other one to the right?

Tags:

I have two <span> elements:

<span style="margin-right:auto;">©2012 XYZ Corp. All Rights Reserved.</span>
<span style="margin-left:auto;">Built with <a href="http://www.wordpress.org/">Wordpress</a> and hosted by <a href="http://www.mediatemple.net/">(mt)</a> in California.</span>

I want the first <span> to be on the left of the page and the second <span> to be on the right side, regardless of page width (so I can't use fixed positioning).

What CSS can I use to do this?

like image 414
antonpug Avatar asked Feb 16 '12 00:02

antonpug


People also ask

How do I align two spans side by side?

The most common way to place two divs side by side is by using inline-block css property. The inline-block property on the parent placed the two divs side by side and as this is inline-block the text-align feature worked here just like an inline element does.

How do you put two spans on the same line?

Maybe try a &nbsp; (non breaking space) in between the spans. Show activity on this post. Overflow maybe? @OP has been set float:left to the span. to make it to be in one line put overflow hidden to the div.

How do you align a span to the right?

Solutions with CSS properties If you want to align a <span> element to the right of the <div>, you can use some CSS. Particularly, you need to use the float property with the “right” and “left” values.


1 Answers

The css variable float is used to position your elements.

The options are:

float:left;
float:right;
float:none;

<span style="float:left;">©2012 XYZ Corp. All Rights Reserved.</span>

<span style="float:right;">Built with <a 

Here is working example:

<span style="float:left; color: red;">©2012 XYZ Corp. All Rights Reserved.</span>

<span style="float:right; color: blue;">Built for example</span>
like image 197
paulcol. Avatar answered Sep 20 '22 03:09

paulcol.