Reputation: 573
OK, I amusing bootstrap and have some thumbnail boxes with text inside (see code bellow).
I also wish to vertically and horizontally align the text, I have done this using flexbox
, this seems to work, however now the span
, h4
and p
tag are all on the same line rather than stacked
.
whats the best way to fix this so i get the tags stacked
but also center both horizontal and vertical.
HTML
<div class="col-md-3 overlord-thumbnail">
<div class="thumbnail">
<a href="#tab4" data-toggle="tab">
<div class="caption">
<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
<h4>Latest News</h4>
<p>text here</p>
</div>
</a>
<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
<h4> Latest News</h4>
<p>text here</p>
</div>
</div>
CSS
.overlord-thumbnail {
height: 188px;
overflow-y: hidden;
overflow-x: hidden;
}
.thumbnail {
background: whitesmoke;
border-radius: 0;
height: 100%;
display: -moz-box;
display: -ms-flexbox;
display: inline-flex;
-moz-box-pack: center;
-ms-flex-pack: center;
-moz-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.caption {
position:absolute;
top:-100%;
right:0;
background: rgba(66, 139, 202, 0.64);
width:100%;
height:100%;
padding:2%;
text-align:center;
color:#fff !important;
z-index:2;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
-ms-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
.thumbnail:hover .caption {
top:0;
}
currently
should be
Upvotes: 0
Views: 53
Reputation: 7766
The problem is that the default styles are overriding the styles you are applying. Use .overlord-thumbnail>.thumbnail
to give it priority.
Also you need to use flex-direction:column;
to get them stacked and not aligned in row next to each other.
.overlord-thumbnail {
height: 188px;
overflow-y: hidden;
overflow-x: hidden;
}
.overlord-thumbnail>.thumbnail{
background: whitesmoke;
border-radius:0;
width:100%;
height: 100%;
display:flex;
flex-direction:column;
align-items:center;
justify-content:center;
text-align:center;
}
.caption {
position:absolute;
top:-100%;
right:0;
background: rgba(66, 139, 202, 0.64);
width:100%;
height:100%;
padding:2%;
text-align:center;
color:#fff !important;
z-index:2;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
-ms-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
.thumbnail:hover .caption {
top:0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="col-md-3 overlord-thumbnail">
<div class="thumbnail">
<a href="#tab4" data-toggle="tab">
<div class="caption">
<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
<h4>Latest News</h4>
<p>text here</p>
</div>
</a>
<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
<h4> Latest News</h4>
<p>text here</p>
</div>
</div>
Upvotes: 1