1

enter image description hereHi I got a problem with aligning 3 icons. I want to align them but everytime I try something like this the first icon starts from the middle of the page but I want there the 2nd icon.

.item-icon {
  width: 10%;
  position: relative;
  display: inline-block;
  text-align: center;
  left: 50%;
  top: 50%;
}

.item-image {
  font-size: 70px;
}
<div class="plan">
  <div class="item-icon">
    <div class="item-image">
      <i class="far fa-lightbulb"></i>
    </div>
    <div class="item-text">
      <p></p>
    </div>
  </div>
  <div class="item-icon">
    <div class="item-image">
      <i class="fas fa-code"></i>
    </div>
    <div class="item-text">
      <p></p>
    </div>
  </div>
  <div class="item-icon">
    <div class="item-image">
      <i class="fas fa-upload"></i>
    </div>
    <div class="item-text">
      <p></p>
    </div>
  </div>
connexo
  • 53,704
  • 14
  • 91
  • 128
Zerry
  • 59
  • 6

4 Answers4

0

add these rules it's a little bit tricky though.

for div.plan

.plan {
    font-size 0:
}

for div.item-icon

.item-icon {
        width: 33.33333%;
        font-size: 1rem;
        text-align: center;
}
ThS
  • 4,597
  • 2
  • 15
  • 27
0

Try margin: auto instead of setting width. Should automatically adjust margins on each side to center it.

.item-icon {
    position: absolute;
    left: 50%;
    }

.item-image {
    position: relative;
    left: -50%;
    display: inline-block;
}
.plan {
    position: relative;
}
Jon Jewett
  • 68
  • 1
  • 7
0
.plan {
  text-align: center;
}

.item-icon {
  display: inline-block;
  position: relative;
  width: 25%;
}
Zerry
  • 59
  • 6
0
.plan {
    text-align: center;
    padding: 24px 0; // optional vertical padding
    margin: 0 -24px; // optional horizontal padding  offset
}

.item-icon {
    position: relative;
    display: inline-block;
    padding: 0 24px; // optional horizontal padding
}

https://codepen.io/themeler/pen/QQoGMa

You've tried to center icon inside icon container (.item-icon) but container has size of an icon, so it won't work as you expect. Also you tried positioning each icon 50% from left and top. That won't work either.

.plan should be your icon container with centered text and icons displayed as 'inline-block's so centering will affect them.

I've added additional padding to both .plan (vertical padding) and icon containers themselves (horizontal padding, to keep them separate).