0

How do I make divs one, two, three horizontal with css?

text-align: center only puts them vertical?

<div class="container">
   <div class="one">One</div>
   <div class="two">Two</div>
   <div class="three">Three</div>
</div>

Js Code:

$(".container").css({
    "position": "fixed", 
    "margin":"0", 
    "left": "0px", 
    "right": "0px", 
    "height": "auto", 
    "min-height": "50px", 
    "z-index": "255", 
    "color": "white", 
    "line-height": "50px", 
    "padding": "16px", 
    "font-size": "1em",
    "text-align": "center", 
    "bottom": "0px", 
    "opacity": "1", 
    "background": "black"
});
fredmaggiowski
  • 2,232
  • 3
  • 25
  • 44
Hbaecklund
  • 261
  • 1
  • 4
  • 16

3 Answers3

1

Set a width and apply display:inline-block in CSS Like this:

.container div {
    width:100px;
    display:inline-block;
}
1

display: inline-block; could make it works.

float: left; will not works because it will puts all your div elements to the left instead of center (it will erase the text-align: center; property you put on .container)

See it here

By the way, why are you applying style with jQuery instead of CSS ?

Vincent G
  • 8,547
  • 1
  • 18
  • 36
0

i think you have to try 'float:left'

DsRaj
  • 2,288
  • 1
  • 16
  • 26