How to align icons with text on the side of Bootstrap 4?

Asked

Viewed 764 times

0

So, I would like to know how I can align the icons with the texts, in this case, the text right in the direction of the center of the icon. I tried it like this, and with some other Bootstrap classes, but some don’t even take effect.

<div class="d-inline-flex justify-content-start align-items-stretch">
                                <div class="col-md-2">
                                    <i class="fas fa-envelope" id="logo-email"></i>
                                </div>
                                <div class="col-md-8 m1-auto align-self-center">
                                    <p class="texto-estilo">texto aqui</p>
                                </div>
                            </div>

But that way they don’t line up, the text always gets too high, or too low, it’s weird. At the moment it’s like this:

inserir a descrição da imagem aqui

  • you can post a fiddle of like this to help you better?

  • of course, just a sec

  • ah, actually I don’t know how to do with bootstrap there in jsfiddle

2 answers

2

2


Your code actually has several problems with Bootstrap. First than the father of a col- must be a row, after the class m1-auto doesn’t exist, I believe you wanted to write m-1. After that to use the type flexbox class align-self-center the container has to be flex, and the col- it’s not flex, so you need to put in col- something like <div class="col-md-8 m-3 d-flex align-items-center">

Now a hint, the tag <p> by default has a margin-botton, something you don’t want! So put in it m-0 That’ll wipe out the margins.

inserir a descrição da imagem aqui

Follow the no-model-aligned only with the classes in Bootstrap! No need for extra CSS! OBS: I changed the configs of col- only to demonstrate here in Snippet, but in your document you can return to col-md-

<link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" />

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css">

    
<div class="container">
    <div class="row">
        <div class="col-1 m-3 d-flex align-items-center">
            <i class="fas fa-envelope" id="logo-email"></i>
        </div>
        <div class="col-8 m-3 d-flex align-items-center">
            <p class="texto-estilo m-0">texto aqui</p>
        </div>
    </div>
</div>

  • 1

    That was perfect. Thank you Ugo, it was very confusing even for me. That solved.

  • 1

    @Giovanemachado tranquilo meu caro, whenever you need a col- seja flex just put the d-flex class in it, then you can use the other flexbox classes to align things inside it... https://getbootstrap.com/docs/4.1/utilities/flex/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.