Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I align spans or divs horizontally?

Tags:

html

css

My only problem is making them line up three-across and have equal spacing. Apparently, spans can not have width and divs (and spans with display:block) don't appear horizontally next to each other. Suggestions?

<div style='width:30%; text-align:center; float:left; clear:both;'> Is what I have now.

like image 832
Thomas Owens Avatar asked Oct 22 '08 14:10

Thomas Owens


People also ask

How can I horizontally align my divs?

To horizontally center a block element (like <div>), use margin: auto; Setting the width of the element will prevent it from stretching out to the edges of its container.

How do I make my span right aligned?

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.

How do you horizontally center text in a span?

Text Align To center an inline element like a link or a span or an img, all you need is text-align: center .

How do you vertically align a span inside a div?

The CSS just sizes the div, vertically center aligns the span by setting the div's line-height equal to its height, and makes the span an inline-block with vertical-align: middle. Then it sets the line-height back to normal for the span, so its contents will flow naturally inside the block.


2 Answers

You can use divs with the float: left; attribute which will make them appear horizontally next to each other, but then you may need to use clearing on the following elements to make sure they don't overlap.

like image 196
jmcd Avatar answered Sep 28 '22 05:09

jmcd


You can use

.floatybox {      display: inline-block;      width: 123px; } 

If you only need to support browsers that have support for inline blocks. Inline blocks can have width, but are inline, like button elements.

Oh, and you might wnat to add vertical-align: top on the elements to make sure things line up

like image 31
runeh Avatar answered Sep 28 '22 04:09

runeh