I see bootstrap do not fix the height of the columns in the row. For example: image 1:1, it will be responsive in the column, but the position of the image is at the top of the row.
If I have text in heading
tag, It have default margins that pushes the text below. So the image will be bonded to the top and the text will be little below the top.
What if I need to normalize the columns and make it aligned in the middle?
My questions is:
What exactly I need to do:
Sorry but it's hard to make it in a jsfiddle, It's includes Angular directives and templates. Just for example:
I have a directive which generates this:
I need to do align the image in the middle, or at least to be at the heading
vertical start. For example:
I made this jsfiddle if you want to experiment. I accept just explanations without any code.
I can fix it with some "hacked" css, but I wanna know how I can do that the right way.
row is now display:flex you can simply use align-self-center on any column to vertically center it... or, use align-items-center on the entire . row to vertically center align all col-* in the row...
1 — Vertical Center Using Auto Margins One way to vertically center is to use my-auto . This will center the element within it's flexbox container (The Bootstrap 4 . row is display:flex ). For example, h-100 makes the row full height, and my-auto will vertically center the col-sm-12 column.
In Bootstrap 5, if we want to vertically align an <div> element in the middle of a containing element, we can do this by applying the class align-items-center and d-flex on the containing element of that div. Here, the d-flex class has the same effect as that of the display: flex; property in CSS.
One approach is to use translateY on the img
element like this:
.v-center {
position: relative;
transform: translateY(50%);
}
You'll also want to put the image inside a col-*-2
..
Demo: http://bootply.com/tVyuhaFoww
Another way to align the image at the top of the first paragraph is to break your design into two rows. The first row contains the header and the second row contains the image, paragraphs and links. This closely resembles your second image above, if that's the way you want it to look.
http://jsfiddle.net/404vska2/
<div class="row">
<div class="col-xs-10 col-xs-push-2">
<h4 class="ng-binding">Monaco make Bernardo Silva move permanent</h4>
</div>
</div>
<div class="row">
<img src="http://s12.postimg.org/gt71dlbd5/1421893782_flat_world_cup_icon_512_Socker_1.png" alt="" class="col-xs-2">
<div class="col-xs-10">
<p class="ng-binding">Bernardo Silva's loan move from SL Benfica to AS Monaco FC has been made permanent, with the 20-year-old settling in well since his summer switch to France.</p>
<span class="rss-news-date ng-binding">Jan 21, 2015</span>
<p><a ng-href="http://www.uefa.com/uefachampionsleague/news/newsid=2204161.html?rss=2204161+Monaco+make+Bernardo+Silva+move+permanent" href="http://www.uefa.com/uefachampionsleague/news/newsid=2204161.html?rss=2204161+Monaco+make+Bernardo+Silva+move+permanent">Lean more</a> </p>
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With