Link to home
Start Free TrialLog in
Avatar of dojjol
dojjolFlag for Afghanistan

asked on

align 2 spans in div horizontally

Hello All,

IS there a way I can align two spans with   in between in a div to align horizontally

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dojjol

ASKER

Thanks gurvinder372. It worked.

But if I enhance the situation like:

In a div I have 4 spans, in which two spans should be aligned horizontally and two vertically, this fails like

<div>
  <span style="padding-right:2px;">column1</span>
  <span>column2</span>
  <span style="padding-right:2px;">column3</span>
  <span>column4</span>
</div>

Can it be possible to have column 3 display under coulmn 1 and coulmn 4 under coulmn 2.

Thanks and appreciated

add a <br> after second column
Yes I would change it like this:

<div>
  <span style="padding-right:2px;">column1</span>
  <span>column2</span><br />
  <span style="padding-right:2px;">column3</span>
  <span>column4</span>
</div>

The spans will keep appending to the "row" that they are in.  Once you insert a <br /> then it will start a new "row" for you to put more <span>'s in.