Reputation: 1029
I am trying to center some text in a row. I feel like this shouldn't be this difficult and I'm confused on why its not working.
Pic(Example)
#title_img {
background-image: url(http://cdn.playbuzz.com/cdn/UserImages/4343091c-c906-457b-b885-77675c22c92f.jpg);
height: 180px;
width: 180px;
margin: 0 auto;
}
#title_img_holder {
padding-top: 5%;
float: none;
margin: 0 auto;
}
#title_holder {
text-align: center;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid" id="header_con">
<div class="container">
<div class="row" id="title_img_holder"> <img src="http://cdn.playbuzz.com/cdn/UserImages/4343091c-c906-457b-b885-77675c22c92f.jpg" class="mx-auto" alt="Smiley face" height="180" width="180"> </div>
<div class="row" id="title_holder">
<h2 class="text-center">We fix screens.
<small class="text-muted">Not for free though</small>
</h2>
</div>
</div>
</div>
I am using the most current version of boostrap 4
Upvotes: 1
Views: 2286
Reputation: 1191
Right now, the display: flex
on .title_holder
is overriding the ability of your <h2>
to fill the full width of its parent automatically. A simple fix would be to set .title_holder h2 { width: 100%; }
, and the text content will then be centered.
#title_img {
background-image: url(http://cdn.playbuzz.com/cdn/UserImages/4343091c-c906-457b-b885-77675c22c92f.jpg);
height: 180px;
width: 180px;
margin: 0 auto;
}
#title_img_holder {
padding-top: 5%;
float: none;
margin: 0 auto;
}
#title_holder {
text-align: center;
}
#title_holder h2 {
width: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid" id="header_con">
<div class="container">
<div class="row" id="title_img_holder"> <img src="http://cdn.playbuzz.com/cdn/UserImages/4343091c-c906-457b-b885-77675c22c92f.jpg" class="mx-auto" alt="Smiley face" height="180" width="180"> </div>
<div class="row" id="title_holder">
<h2 class="text-center">We fix screens.
<small class="text-muted">Not for free though</small>
</h2> </div>
</div>
</div>
Upvotes: 1
Reputation: 67738
Add this CSS:
#title_holder h2 {
margin: 0 auto;
}
(You have to center the h2 inside its parent container)
http://codepen.io/anon/pen/QpqQYq
Upvotes: 5