0

How to move

<div class="rate1"></div>
<div class="info"></div>
<div class="rate2"></div>

to center of div class="bottom" ?


.bottom {
  float: left;
  width: 100%;
  border: 1px solid #ccc;
}

.rate1 {
  width: 70px;
  height: 70px;
  border-radius: 70px;
  border: 5px solid #f0f0f0;
  float: left;
  box-shadow: 1px 1px 1px 0px #e9e9e9;
  background: url(http://web.arjentienkamp.com/codepen/tinder/delete.png);
  margin-left: 4px;
  background-size: 25px;
  background-position: center;
  background-repeat: no-repeat;
}

.info {
  width: 40px;
  height: 40px;
  float: left;
}

.rate2 {
  width: 70px;
  height: 70px;
  border-radius: 70px;
  border: 5px solid #f0f0f0;
  float: left;
  box-shadow: 1px 1px 1px 0px #e9e9e9;
  background: url(http://web.arjentienkamp.com/codepen/tinder/heart.png);
  margin-left: 4px;
  background-size: 25px;
  background-position: center;
  background-repeat: no-repeat;
}
<div class="bottom">
  <div class="rate1"></div>
  <div class="info"></div>
  <div class="rate2"></div>
</div>
Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
tempori
  • 45
  • 5

2 Answers2

4

Use flexbox

.bottom{
    width: 100%;
    border: 1px solid #ccc;
    display: flex;
    justify-content: center;
    align-items: center;
}
.rate1{
    width: 70px;
    height: 70px;
    border-radius: 70px;
    border: 5px solid #f0f0f0;
    box-shadow: 1px 1px 1px 0px #e9e9e9;
    background: url(http://web.arjentienkamp.com/codepen/tinder/delete.png);
    margin-left: 4px;
    background-size: 25px;
    background-position: center;
    background-repeat: no-repeat;
}
.info{
    width: 40px;
    height: 40px;
}
.rate2{
    width: 70px;
    height: 70px;
    border-radius: 70px;
    border: 5px solid #f0f0f0;
    box-shadow: 1px 1px 1px 0px #e9e9e9;
    background: url(http://web.arjentienkamp.com/codepen/tinder/heart.png);
    margin-left: 4px;
    background-size: 25px;
    background-position: center;
    background-repeat: no-repeat;
}
<div class="bottom">
    <div class="rate1"></div>
    <div class="info"></div>
    <div class="rate2"></div>
</div>
Athul Nath
  • 2,536
  • 1
  • 15
  • 27
0

You can do this easily with flexbox :

.bottom {
  display : flex;
  justify-content : center;
}

You should also consider to remove the float : left; in the inner divs.

You can also check the css-tricks's centering guide for other use case.

Palisanka
  • 447
  • 4
  • 10