DummyBeginner
DummyBeginner

Reputation: 431

define float as center in css

How can I define a define float as center in css? actually i need a layout between right and left and also i tried "text-align" but it doesn't work and the "float" property just working.

Thank you

Upvotes: 1

Views: 795

Answers (3)

yopefonic
yopefonic

Reputation: 532

There is no float: center. but when you want a div to be centered to its parent this should do the trick:

#parent-element{
    position: relative;
}
#element
{
  width: 500px; 
  left: 50%;
  margin-left: -250px; /* - (width/2)  */
  position: absolute;
}

but, what exactly are you trying to achieve?

Upvotes: 1

David Snabel-Caunt
David Snabel-Caunt

Reputation: 58361

You want something like this:

<div style="width: 500px; text-align: center;">

    <div style="margin: 0 auto; width: 100px;">I am centered</div>

</div>

The key is text-align: center on the parent, and a margin: 0 auto on the inner element

Upvotes: 10

Palo Verde
Palo Verde

Reputation: 377

You can only float an element to the left or the right.

Maybe describe what kind of layout you are trying to achieve.

Upvotes: 0

Related Questions