Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to center a css sprite inside a div?

I created a css sprite to combine several images appearing on my homepage. However I now have issues displaying those images.

enter image description here

You see that the images (store logos) are not displayed centrally. Here is my html code:

           <div class="slider-slick">
               <?php foreach($stores as $store){?>
                    <div class="slide">
                        <div class="client">
                            <div class="sprite sprite-<?php echo $store->_storeName?>"></div>
                        </div>
                    </div>
               <?}?>
            </div>

The css for the sprite is:

.sprite {
    background-image: url(../images/spritesheet-logos.png);
    background-repeat: no-repeat;
    margin: auto;
}

.sprite-store1 {
    width: 149px;
    height: 71px;
    background-position: -5px -5px;
}

.sprite-store2 {
    width: 148px;
    height: 23px;
    background-position: -164px -5px;
}

and the parent div is:

.client {
    padding: 70% 0 0;
    background: #ffffff;
}

After removing the padding they look like:

enter image description here

I've been trying all different options with margin but couldn't really make it. Any ideas how to make them look like this?

enter image description here

like image 334
panipsilos Avatar asked Dec 07 '25 16:12

panipsilos


1 Answers

Try using flexbox:

.client {
  display: flex;
  justify-content: center;
  align-items: center;
}
like image 147
Stickers Avatar answered Dec 11 '25 15:12

Stickers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!