Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

How can I show 3 columns, but keep them aligned in the center?

Below is the link of what I have tried so far.

https://jsfiddle.net/m_zaid/hnfrLaf6/

 

Now the requirement is, I need to show all3 div should be center align also. 

Any help in this regards will be highly appreciated.

 

Thanks in advance.

Regard,

Muhammad Zaid.

user-image
Question added by Muhammad Zaid , Senior Front End Developer , Royaltri Inc.
Date Posted: 2017/03/28

<div class="wrapper">

  <div class="box one"></div>

  <div class="box two"></div>

  <div class="box three"></div>

</div>

.wrapper {

  display:flex;

  font-size: 0;

  justify-content:center;

}

 

.box {

  width: 20%;

  background-color: #f00;

  min-height: 200px;

}

 

.two {

  background-color: #ff0;

}

 

.three {

  background-color: #fff;

 

}

 

Ashraf CA
by Ashraf CA , DIGITAL MARKETING & MULTIMEDIA DESIGNER , Standard Marconi DMCC

The below is the easy fix, but not a permanent solution.

https://jsfiddle.net/12yn26x3/

 

HTML

 

div class="wrapper" align="center">

  <div class="box one"></div>

<div class="box two"></div>

<div class="box three"></div>

</div>

 

 

CSS

 

.box {width: 20%; background-color: #f00; min-height: 200px;display:inline-block;}

.two {background-color: #ff0;display:inline-block;}

.three {background-color: #fff;}

<divclass="wrap"><divclass="left"> left </div><divclass="right"> right </div><divclass="center"> center sdv dg sdb sdfbh sdfhfdhh h dfh </div></div>

Muhammad Zaid
by Muhammad Zaid , Senior Front End Developer , Royaltri Inc.

Dear Ashraf,

Your solution leads me to make it work for me.

https://jsfiddle.net/m_zaid/hnfrLaf6/1/

Also, I have notice that while I am using display: inline-block, it's giving gaps between boxes, so I have given font-size:0 on the wrapper. This will remove gaps between boxes.

Thanks for the help.

Regards,

Muhammad Zaid.

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.