Renish Khunt
Renish Khunt

Reputation: 5824

CSS float left with margin auto on div?

hello friends can i set float:left with the margin:auto

this is my html code

<div class='gallary'>
      <div>1</div>
      <div>2</div>
      <div>3</div>
      <div>4</div>
</div>

my css code this is not working.

.gallary{
     width:100%;
 }
 .gallary div{
       float:left;
       margin:0 auto;
  }

please help. Thank you.

Upvotes: 10

Views: 22798

Answers (4)

Bradley Tenuta
Bradley Tenuta

Reputation: 31

I tested it and got it working, all you have to do is:

.gallary{
    width: 100%;
    text-align: Center;
}
.gallary div{
    display: Inline-block;
}

Upvotes: 1

user2050308
user2050308

Reputation:

try this is very help fully. i hop this is used full for you.

.gallary{
 width:100%;
 }

.gallary div{
       vertical-align:top;
       display:inline-block;
       margin:0 auto;
}

Upvotes: 8

Maloke
Maloke

Reputation: 224

Try using display: inline-block; to maintain the divs at the same line and text-align:center; do align to the center:

Here's the fix: http://jsfiddle.net/4xxvb/3/

Upvotes: 5

CRABOLO
CRABOLO

Reputation: 8793

just use inline-block instead of float

.gallary div {
    display: inline-block;
    margin: 0 auto;
}

Upvotes: 8

Related Questions