Kuzma
Kuzma

Reputation: 711

FlexBox: align icons by left corner and keep same gap after them

I have flexbox container with items. They are both horizontally and vertically aligned by center. This is normally rendered on a live website. However I need to align font awesome icons with text in such way: 1). All icons are aligned by the left corner
2). The gap which goes after icons and before text must have the same length.

Here is a CodePen with a draft

So it's shown that icons are not aligned properly.

Code:

.contact-container {   
  display: -ms-flexbox;
  -ms-flex-wrap: wrap;
  -ms-flex-direction: column; 
  -webkit-box-orient: horizontal; 
  -webkit-box-direction: normal; 
      -ms-flex-flow: row wrap; 
          flex-flow: row wrap; 
  display: -webkit-box;
  display: flex;  
}
.contact-container .copy {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  justify-content: center;  
  -webkit-box-align:center;
      -ms-flex-align:center;
          align-items:center;
}

.contact-container .fa {
  font-size: 40px;    
  -ms-flex-negative: 0;    
      flex-shrink: 0;  
  padding-left:20px;
}
.contact-container .item > *{color: #9f6a4a;}
.contact-container .item { 
   -webkit-box-flex: 0; 
    flex: 0 1 100%;
  -ms-flex: 0 1 100%;
  flex: 0 1 47%; 
  background:#fff;
  color:#fff;      
}
.contact-container .item{
    /*height: calc(720px/4);*/
    -ms-flex-item-align: center;
        align-self: center;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
        -ms-flex-direction: column;
            flex-direction: column;
    text-align: center;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-wrap: wrap;
        flex-wrap: wrap;
    -webkit-box-pack: center;
        -ms-flex-pack: center;
            justify-content: center;
    /*min-height: 100%;*/
    min-width: 50%;
}
.contact-container h2{font-size:1.1em;font-weight:500;}
.contact-container h3 {padding-left: 10px;}

Upvotes: 1

Views: 1239

Answers (1)

Matthew Moore
Matthew Moore

Reputation: 866

By definition, you can't left-justify objects that are centered. You would have to set the parent container to left align the icon/text, then give a left margin/width to allow for them to match up - as each individual container is again in another container.

EDIT: A rough example, here:

.contact-container {   
  display: flex;
  flex-flow: row wrap;
  align-items: center;
}

.item {
  width: 50%;
}

.item > * {
  color: #9f6a4a;
}


.copy {
  display: flex;
  flex-direction: row;
  align-items: center;
  width: 70%;
  margin: auto;
}

h3 {
  margin: 0 .5em;
}

i.fa {
  font-size: 40px;
  padding-left:20px;
}













/* IGNORE THIS - for illustrative purpose only */
.item:nth-child(1), .item:nth-child(4) {
  background-color: #DFD;
}

.item:nth-child(2), .item:nth-child(3) {
  background-color: #DDF;
}
<script src="https://use.fontawesome.com/97dc0a8baa.js"></script>
<div class="contact-container">
    <div class="item">
        <div class="box">
            <div class="inner">
                <div class="copy"> <i class="fa fa-mobile-phone"></i>
                    <h3 class="sppb-addon-title sppb-feature-box-title sppb-media-heading"><a href="tel:+37068713383">+1 123 45 678 99</a></h3></div>
            </div>
        </div>
    </div>
    <div class="item">
        <div class="box">
            <div class="inner">
                <div class="copy"> <i class="fa fa-envelope-o"></i>
                    <h3 class="sppb-addon-title sppb-feature-box-title sppb-media-heading"> <span>[email protected]</span></h3></div>
            </div>
        </div>
    </div>
    <div class="item">
        <div class="box">
            <div class="inner">
                <div class="copy"> <i class="fa fa-map-marker"></i>
                    <h3 class="sppb-addon-title sppb-feature-box-title sppb-media-heading">City, Street 22</h3></div>
            </div>
        </div>
    </div>
    <div class="item">
        <div class="box">
            <div class="inner">
                <div class="copy"> <i class="fa fa-calendar"></i>
                    <h3 class="sppb-addon-title sppb-feature-box-title sppb-media-heading">I-V 09:00-17:00<br>&nbsp;VI 09:00-14:00<br>VII closed</h3></div>
            </div>
        </div>
    </div>
</div>

Upvotes: 1

Related Questions