anais_stemb
anais_stemb

Reputation: 103

Several images with title

I have a background with an image, in this bakground I have 3 images with 3 numbers. I would like for each number, center the number with the image.
I am stuck with the property margin-left

.background-picture-red{
  height: 130px;
  width: 100%;
  position: absolute;
  background-image: url(https://i.ibb.co/jVWdfG4/bg-2.jpg);
}

.picture01{
  border: 1px solid #fff;
  padding: 10px;
  border-radius: 50%;
  background-color: rgba(224,0,0,0.30);
  float:left;
  margin-top: 10px;
  margin-left: 50px;
  z-index: 1;
  position: relative;
}

.picture01-title{
  font-family: 'Questrial', sans-serif;
  font-size: 16px;
  color: white;
  margin-left: 50px;
  margin-top: 100px;
  position: absolute;
}

.picture02{
  border: 1px solid #fff;
  padding: 10px;
  border-radius: 50%;
  background-color: rgba(224,0,0,0.30);
  float:left;
  margin-top: 10px;
  margin-left: 60px;
  z-index: 1;
  position: relative;
}

.picture02-title{
  font-family: 'Questrial', sans-serif;
  font-size: 16px;
  color: white;
  margin-left: 50px;
  margin-top: 100px;
  position: absolute;
}

.picture03{
  border: 1px solid #fff;
  padding: 10px;
  border-radius: 50%;
  background-color: rgba(224,0,0,0.30);
  float:left;
  margin-top: 10px;
  margin-left: 70px;
  z-index: 1;
  position: relative;
}

.picture03-title{
  font-family: 'Questrial', sans-serif;
  font-size: 16px;
  color: white;
  margin-left: 10px;
  margin-top: 100px;
  position: absolute;
}
<div class="background-picture-red"> 
   <img class="picture01" src="https://i.ibb.co/n3fv0YY/bitcoin34.png">
   <span class="picture01-title">138</span>
   <img class="picture02" src="https://i.ibb.co/qRSr1Wr/bitcoin46.png">
   <span class="picture02-title">258</span>
   <img class="picture03" src="https://i.ibb.co/BwT7gHz/bitcoin68.png">
   <span class="picture03-title">303</span>
</div>

Upvotes: 0

Views: 23

Answers (1)

Maarti
Maarti

Reputation: 3719

Here is a working example where I added to each title:

  margin-left: -43px;
  transform:translateX(-50%);
  • margin-left: -43px : because your image size is 86px so -43px will be placed in the middle of the image
  • translateX(-50%) : so the text will be centered depending of its own size

.background-picture-red{
  height: 130px;
  width: 100%;
  position: absolute;
  background-image: url(https://i.ibb.co/jVWdfG4/bg-2.jpg);
}

.picture01{
  border: 1px solid #fff;
  padding: 10px;
  border-radius: 50%;
  background-color: rgba(224,0,0,0.30);
  float:left;
  margin-top: 10px;
  margin-left: 50px;
  z-index: 1;
  position: relative;
}

.picture01-title{
  font-family: 'Questrial', sans-serif;
  font-size: 16px;
  color: white;
  margin-left: -43px;
  transform:translateX(-50%);
  margin-top: 100px;
  
  position: absolute;
}

.picture02{
  border: 1px solid #fff;
  padding: 10px;
  border-radius: 50%;
  background-color: rgba(224,0,0,0.30);
  float:left;
  margin-top: 10px;
  margin-left: 60px;
  z-index: 1;
  position: relative;
}

.picture02-title{
  font-family: 'Questrial', sans-serif;
  font-size: 16px;
  color: white;
  margin-left: -43px;
  transform:translateX(-50%);
  margin-top: 100px;
  position: absolute;
}

.picture03{
  border: 1px solid #fff;
  padding: 10px;
  border-radius: 50%;
  background-color: rgba(224,0,0,0.30);
  float:left;
  margin-top: 10px;
  margin-left: 70px;
  z-index: 1;
  position: relative;
}

.picture03-title{
  font-family: 'Questrial', sans-serif;
  font-size: 16px;
  color: white;
  margin-left: -43px;
  transform:translateX(-50%);
  margin-top: 100px;
  position: absolute;
}
<div class="background-picture-red"> 
   <img class="picture01" src="https://i.ibb.co/n3fv0YY/bitcoin34.png">
   <span class="picture01-title">138</span>
   <img class="picture02" src="https://i.ibb.co/qRSr1Wr/bitcoin46.png">
   <span class="picture02-title">258</span>
   <img class="picture03" src="https://i.ibb.co/BwT7gHz/bitcoin68.png">
   <span class="picture03-title">303</span>
</div>


But maybe you should use flexbox to do that kind of thing.

Upvotes: 1

Related Questions