How to place an icon in between two bootstrap columns?

Viewed 512

I would like to place an icon, centered, in between two bootstrap columns that are both on one row? The columns are each col-6 and that cannot change. I would like this icon to always be between the two columns on mobile and on desktop etc. How can I accomplish this?

<a class="row bg-light" href="#">
    <div class="col-lg-6 ">
        <!-- stuff -->
    </div>

    I want an Icon here like: <i class="fa-bla"></i>

    <div class="col-lg-6 ">
        <!-- stuff -->
    </div>
</a>
3 Answers

You can call font awesome directly from css by using the unicode. If you give the div an id, you can use ::after to add the icon like so:

#stuff::after {
  font-family: "FontAwesome";
  content: "\f007";
  vertical-align: middle;
}
<link href="https://use.fontawesome.com/releases/v5.0.1/css/all.css" rel="stylesheet">

<a class="row bg-light" href="#">
  <div id="stuff" class="col-lg-6 ">
    <!-- stuff -->
  </div>
  <div class="col-lg-6 ">
    <!-- stuff -->
  </div>
</a>

If you don't find a better solution, then I would try using:

display: grid;
grid-template-columns: 45% 5% 45%;

(or however you need the dimensions to be to fill the page up)

And then maybe flex the icon to position it centrally:

display: flex;
justify-content: center;
align-items: center;

Changing up the col-X in Bootstrap would work too, but you said they can't be changed, so... I do hope you make it work though.

Using CSS you could do something like:

<a class="row bg-light" href="#">
    <div class="col-lg-6 has-icon">
        <!-- stuff -->
        <i class="fa-bla"></i>
    </div>
    <div class="col-lg-6">
        <!-- stuff -->
    </div>
</a>

.has-icon {
    position: relative;
}
.has-icon i {
    position: absolute;
    top: 50%;
    margin-top: -10px; // half of the icon's height 
    left: -10px; // will need adjusting to preference
}

You will also need to consider re-positioning when the columns collapse on smaller devices, so using media query and placing the icon to the bottom of the first column instead.

Related