0

Text is on center but image is not. How can i fix it?

.advantage-first__block {
  position: absolute;
  bottom: 0;
  left: 25px;
  right: 25px;
  width: 150px;
  height: 150px;
}

.advantage-first__block img {
  text-align: center;
  right: 0;
  left: 0;
  margin: 0 auto;
  width: 60px;
  height: 24px;
}

.advantage-information {
  margin: 0 auto;
  width: 129px;
  height: 76px;
  text-align: center;
  right: 0;
  left: 0;
}
<div class="advantage__info">
  <div class="advantage-first__block">
    <img class="advantage-src" src="images/advantage-car.png" alt="">
    <div class="advantage-information">
      Более 300 автомобилей в вашем распоряжении
    </div>
  </div>
</div>

Text is on center but image is not. How can i fix it?

Sfili_81
  • 2,061
  • 5
  • 22
  • 34
  • add `text-align: center;` in `advantage-first__block ` – Minal Chauhan Feb 04 '21 at 11:01
  • I wrote a whole answer b4 it was closed... Im pretty upset, but here's part of it.. B"H There are different ways to center an image, or anything really, a good way I've found is to move it `50%` to the `left` and `top`, and at the same time, `transform` it to `translate` `50%` of its own width, on the x and y axes, to account for the offset. – B''H Bi'ezras -- Boruch Hashem Feb 04 '21 at 11:08
  • .advantage-first__block{ position: absolute; left: 25px; right: 25px; width: 150px; height: 150px; } .advantage-first__block img{ display:inline-block; width: 60px; height: 24px; } .advantage-information{ width: 129px; height: 76px; text-align: center; } .emtzuh { position:absolute; left:50%; top:50%; transform:translate(-50%,-50%); } – B''H Bi'ezras -- Boruch Hashem Feb 04 '21 at 11:08
  • Более 300 автомобилей в вашем распоряжении
    – B''H Bi'ezras -- Boruch Hashem Feb 04 '21 at 11:08

1 Answers1

0

Add text-align: center; in advantage-first__block

.advantage-first__block{
  position: absolute;
  bottom: 0;
  left: 25px;
  right: 25px;
  width: 150px;
  height: 150px;
  text-align: center;
  background: skyblue;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.advantage-first__block img{
  text-align: center;
  right: 0;
  left: 0;
  margin: 0 auto;
  width: 60px;
  height: 24px;
}
.advantage-information{  
  margin: 0 auto;
  width: 129px;
  height: 76px;
  text-align: center;
  right: 0;
  left: 0;
}
<div class="advantage__info">
    <div class="advantage-first__block">
        <img class="advantage-src" src="https://via.placeholder.com/50" alt="">
        <div class="advantage-information">
            Более 300 автомобилей 
            в вашем распоряжении
        </div>
    </div>
</div>
Minal Chauhan
  • 5,982
  • 8
  • 20
  • 39