0

I have a problem with float:left

<div class="gallery">
            <img src="img.jpg" alt="">
            <img src="img.jpg" alt="">
            <img src="img.jpg" alt="">
</div>

How to center them all using float:left

.gallery {
    margin: 0 auto;
}
.gallery > img {
    display: block;
    margin: 0 auto;
    float: left;
}

Tried this and few others codes ex. used box-sizing:border-box but without result.

Seems like margin auto doesn't work after using float.

I know i can center that just using inline-block and text-align:center but i want to center them using float.

How i can fix this using float ?

Kamil
  • 40
  • 8
  • `I know i can center that just using inline-block and text-align:center` : this is the answer you will get. Float is for float not for centring, you are simply complicating things – Temani Afif Aug 07 '18 at 23:39
  • duplicate of : https://stackoverflow.com/questions/4767971/how-do-i-center-float-elements – Temani Afif Aug 07 '18 at 23:40
  • and of : https://stackoverflow.com/questions/5523632/aligning-a-floatleft-div-to-center – Temani Afif Aug 07 '18 at 23:40
  • 1
    Possible duplicate of [How do I center float elements?](https://stackoverflow.com/questions/4767971/how-do-i-center-float-elements) – Roy Scheffers Aug 07 '18 at 23:45

0 Answers0