So when using a css framework like bootstrap, it is always recommended to write as little as possible of css.
Bootstrap defaults to all Divs that do not have a size specification (type col-2
, col-5
) have width of 100%. therefore, you do not need to put that col-12
that you’re wearing, so I’ve taken.
The other thing is that the font-awesome class is kind of wrong with the "s" so I took the s too, got fa fa-phone fa-lg
.
EDIT: Actually this was a mistake of mine, I was considering version 4 of fontawesome. I corrected my error in snippet
With those considerations in mind, the only thing you have to do is put the two elements in separate Ivs:
- the text you want centralized within a div with class
text-center
;
- the icon inside a div with class
position-absolute
;
and works right:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script defer src="https://use.fontawesome.com/releases/v5.0.8/js/solid.js" integrity="sha384-+Ga2s7YBbhOD6nie0DzrZpJes+b2K1xkpKxTFFcx59QmVPaSA8c7pycsNaFwUK6l" crossorigin="anonymous"></script>
<script defer src="https://use.fontawesome.com/releases/v5.0.8/js/fontawesome.js" integrity="sha384-7ox8Q2yzO/uWircfojVuCQOZl+ZZBg2D2J5nkpLqzH1HY0C1dHlTKIbpRz/LG23c" crossorigin="anonymous"></script>
<div class="card">
<div class="card-body">
<h5 class="card-title">Pizzaria 1</h5>
<hr class="ml-3 mr-3">
<div class="no-gutters bg-secondary">
<div class="position-absolute">
<i class="fas fa-phone fa-lg"></i>
</div>
<div class="card-text text-center">
<h6>(27) 3974-514</h6>
</div>
</div>
<p>segunda linha</p>
</div>
</div>
As final considerations, although you didn’t ask that:
It is worth noting that bootstrap4 has this utility of, if you want to put margin on both sides (left and right), you can use the class mx-3
that is, "X-axis margin of size 3", the same logic works for the Y-axis, applied to both margin and padding.
It is recommended that all card text is inside the div with class card-body
, so they have that margin for the margin of card
(which I also added to the snippet, if you don’t want it, just take the first div).
Just a detail, he wants the text centered, and his fontawesome was right, because it was in version 5, what you did was pass his icon to old version that eh a 4....
– hugocsl
fault mine, but as far as I saw, works in both versions
– vhoyer
I think you should see the documentation of version 5 to know what is this "S" that you took...
– hugocsl
truth, do you think I should remove the answer? being that at the end of the day I didn’t answer his question...
– vhoyer
Young this is up to you, you can edit, remove, or leave like this. I just gave you a hint about the new version of the font. If you think your answer answers the question or you can help someone else with similar problems leave it there... you decide this...
– hugocsl
I like to use the bootstrap classes, only removed the textcenter of the div that has the phone, is redundant
– Igor Oliveira