I have a div that contains two children, each of which is framed using bootstrap’s columns. However, within these divs, what I need to be able to do is that for the left div, I have some icons that need to vertically aligned and centered relative to the div to the right.
The div to the right contains an anchor tag that acts as a button, and has some padding. This causes the button to extend downwards, and the left div doesn’t occupy the remaining height.
I have attached here a
codepen
to show what I am talking about.
.shareContainer {
padding: 28px 0px;
}
.row {
background: #eee !important;
}
.fa-icon {
margin-left: 20px;
font-size: 2.2em;
color: #ff7350;
}
.button {
display: inline-block;
padding: 18px 50px;
padding-right: 30px;
font-size: 17px;
font-weight: 400;
font-family: "Lato";
border-radius: 2px;
letter-spacing: 0.01em;
color: #fff !important;
text-transform: uppercase;
background-color: #fb8669;
box-shadow: none;
border: none;
}
.arrowRight {
float: right;
margin-left: 20px;
}
.button:active,
.button:focus,
.button:hover {
text-transform: uppercase;
color: #fff;
text-decoration: none;
cursor: pointer;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class='container shareContainer'>
<div class='row'>
<div class="col-sm-8">
<i class='fa fa-share-square-o fa-icon'></i>
<i class='fa fa-facebook-square fa-icon'></i>
<i class='fa fa-twitter fa-icon'></i>
</div>
<div class="col-sm-4">
<a target="_blank" class='button' }>
register for event <svg class='arrowRight'width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" id="arrow-right"><path d="M9 4l7 8-7 8" stroke="currentColor" stroke-width="2" fill="none" fill-rule="evenodd"></path></svg>
</a>
</div>
</div>
</div>
4
Answers
Use
flexbox
to vertically align elements:Codepen demo: https://codepen.io/anon/pen/oeZVoa
You’ll just need to apply these built-in Bootstrap 4 classes to the LHS div with the icons
So, now the
shareContainer
div will look like this:Here’s a Codepen
What it does basically is apply these CSS properties:
You could just add a
margin:auto;
to the surrounding container:Demo: JSFiddle
You can use flexbox for your centering