Equal Height Column Working Only On Desktop - html

I have code in my bootstrap 5 website like this
<div class="row mt-3">
<div class="col-md-6 mt-3 mt-md-0">
<a href="post/good-morning-status-shayari-68346" class="h-100"><img src="https://via.placeholder.com/500x500/" class="img-fluid blog-img lzy_img" alt="Good Morning Status Shayari" width="100%" height="100%">
</a>
</div>
<div class="col-md-6 mt-3 mt-md-0">
<div class="bg-dark text-white blog_content d-flex flex-column bg-black h-100 text-center pt-3 pb-3 px-3 mx-3">
<h5>સપનાઓ ચા જેવા કડક હોવા </h5>
<div class="d-flex flex-grow-1 justify-content-center align-items-center mb-0">
<div class="">
<p class="">સપનાઓ ચા જેવા<br> કડક હોવા જોઈએ સાહેબ,<br> જે રાતની ઊંઘ છીનવી લે !!<br> 💐🌷🌹શુભ સવાર🌹🌷💐</p>
</div>
</div>
<div class="time d-flex justify-content-between align-items-center align-items-end mt-auto border-top pt-3">
<div class="left text-start">
<h6 class="mb-0"><a class="link-bold" href="https://stag.example.com/gu/category/gujarati-good-morning-status-shayari">શુભ સવાર સ્ટેટસ શાયરી</a></h6>
<p class="mb-0"><small>6 days ago</small></p>
</div>
<div class="right">
</div>
</div>
</div>
</div>
</div>
Its working fine and output like this in desktop:
But in Mobile doesn't have equal height and it's looking like:
Basically I want same height column as image in mobile device too but its not working. I am using bootstrap 5.2.
I have added code in codeplay for text.
Let me know if someone here can help me for solve the puzzle.

This can easily be accomplished by using the aspect ratio helper classes. Just apply .ratio.ratio-1x1 to the inner wrapper within the .col-md-6s.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<div class="row mt-3">
<div class="col-md-6 mt-3 mt-md-0">
<a href="post/good-morning-status-shayari-68346" class="h-100 ratio ratio-1x1"><img src="https://via.placeholder.com/500x500/" class="img-fluid blog-img lzy_img" alt="Good Morning Status Shayari" width="100%" height="100%">
</a>
</div>
<div class="col-md-6 mt-3 mt-md-0">
<div class="bg-dark text-white blog_content d-flex flex-column bg-black h-100 text-center pt-3 pb-3 px-3 mx-3 ratio ratio-1x1">
<h5>સપનાઓ ચા જેવા કડક હોવા </h5>
<div class="d-flex flex-grow-1 justify-content-center align-items-center mb-0">
<div class="">
<p class="">સપનાઓ ચા જેવા<br> કડક હોવા જોઈએ સાહેબ,<br> જે રાતની ઊંઘ છીનવી લે !!<br> 💐🌷🌹શુભ સવાર🌹🌷💐</p>
</div>
</div>
<div class="time d-flex justify-content-between align-items-center align-items-end mt-auto border-top pt-3">
<div class="left text-start">
<h6 class="mb-0"><a class="link-bold" href="https://stag.example.com/gu/category/gujarati-good-morning-status-shayari">શુભ સવાર સ્ટેટસ શાયરી</a></h6>
<p class="mb-0"><small>6 days ago</small></p>
</div>
<div class="right">
</div>
</div>
</div>
</div>
</div>

.col-md-6 img {height: 100%;}
.col-md-6 { text-align: center; height:500px; }

Related

Bootstrap 5 justify-content not working correctly and cannot vertically center content

I have the following piece of code and I am use bootstrap 5:
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
<br><br>
<div class="list-group-item d-flex flex-row">
<div class="flex-column">
<h4>A Test Recipe</h4>
<p>This is simply a test</p>
</div>
<div class="flex-row align-self-center justify-content-end">
<img src="https://cdn.pixabay.com/photo/2016/06/15/19/09/food-1459693_1280.jpg"
alt="A Test Recipe"
style="max-height: 50px !important">
</div>
</div>
I'm trying to get the image to the end of list-group-item div. I tried using justify-content-end but this has no effect. I also tried align-self-end this also doesn't bring the image to the right side.
And as for the div with the flex-column class I'm trying to vertically center its content. But it's not working either, it should be centered like the image is. I got the image vertically centered by making use of the align-self-center class. However when I apply this class to the div that has flex-column class it doesn't work.
What am I doing wrong?
؟
<linkhref="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="list-group-item d-flex justify-content-center align-items-center flex-wrap">
<div class="card m-3 border-0" style="max-width: 250px;">
<div class="row g-0">
<div class="col-5">
<img src="https://cdn.pixabay.com/photo/2016/06/15/19/09/food-1459693_1280.jpg"
class="img-fluid rounded-5"
alt="A Test Recipe">
</div>
<div class="col-7">
<div class="card-body">
<h5 class="card-title">A Test Recipe </h5>
<p class="card-text">This is simply a test.</p>
</div>
</div>
</div>
</div>
</div>
try this.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
<br><br>
<div class="list-group-item d-flex justify-content-center align-items-center flex-wrap">
<div class="card m-3 border-0" style="max-width: 350px;">
<div class="row g-0">
<div class="col-5">
<img src="https://cdn.pixabay.com/photo/2016/06/15/19/09/food-1459693_1280.jpg"
class="img-fluid rounded-3"
alt="A Test Recipe">
</div>
<div class="col-7">
<div class="card-body">
<h5 class="card-title">A Test Recipe </h5>
<p class="card-text">This is simply a test.</p>
</div>
</div>
</div>
</div>
</div>

How to set the backgroundcolor of a Bootstrap card fo the whole column?

I've got a questtion about the Bootstrap Card Deck.
I create a Card Deck with two cards in a row. On the first card I've got some text under the header and in the second card there is no text under the header. In this case the grey color does not fill the whole card as you can see in the example. How can I fix it, that the hole column is also grey?
Thanks for your help!
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.11.0/css/mdb.min.css">
<div class="card-deck mb-5">
<a href="#" class="card hoverable">
<div class="card-body p-0">
<div class="row mx-0">
<div class="col-md-8 grey lighten-4 rounded-left pt-2">
<h5 class="font-weight-bold">Header</h5>
<p class="font-weight-light text-muted mb-2">Some text</p>
</div>
<div class="col-md-4 text-center pt-3">
<p class="h2 font-weight-normal">60</p>
</div>
</div>
</div>
</a>
<a href="#" class="card hoverable">
<div class="card-body p-0">
<div class="row mx-0">
<div class="col-md-8 grey lighten-4 rounded-left pt-2">
<h5 class="font-weight-bold">Header</h5>
<!-- <p class="font-weight-light text-muted mb-2">No text</p> -->
</div>
<div class="col-md-4 text-center pt-3">
<p class="h2 font-weight-normal">50</p>
</div>
</div>
</div>
</a>
</div>
If you want to have the height be equals the container, you can use h-100 on the div row mx-0.
More information can be found here: https://getbootstrap.com/docs/4.0/utilities/sizing/
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.11.0/css/mdb.min.css">
<div class="card-deck mb-5">
<a href="#" class="card hoverable">
<div class="card-body p-0">
<div class="row mx-0">
<div class="col-md-8 grey lighten-4 rounded-left pt-2">
<h5 class="font-weight-bold">Header</h5>
<p class="font-weight-light text-muted mb-2">Some text</p>
</div>
<div class="col-md-4 text-center pt-3">
<p class="h2 font-weight-normal">60</p>
</div>
</div>
</div>
</a>
<a href="#" class="card hoverable">
<div class="card-body p-0">
<div class="row h-100 mx-0">
<div class="col-md-8 grey lighten-4 rounded-left pt-2">
<h5 class="font-weight-bold">Header</h5>
<!-- <p class="font-weight-light text-muted mb-2">No text</p> -->
</div>
<div class="col-md-4 text-center pt-3">
<p class="h2 font-weight-normal"></p>
</div>
</div>
</div>
</a>
</div>
Ideally you should not play around with left/right margins of row and col in bootstrap. You should use no-gutters class with row to have the effect you want. Additionally, you should add h-100 on the second row to take full height. Also a better way to center align your number is like I have done in the snippet by using justify-content-center d-flex align-items-center.
Also your code was missing a container element so that scrollbar was coming in your snippet. I have added that too.
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.11.0/css/mdb.min.css">
<div class="container">
<div class="card-deck mb-5">
<a href="#" class="card hoverable">
<div class="card-body p-0">
<div class="row h-100 no-gutters">
<div class="col-md-8 grey lighten-4 rounded-left">
<h5 class="font-weight-bold p-2">Header</h5>
<p class="font-weight-light text-muted mb-2 px-2">Some text</p>
</div>
<div class="col-md-4 text-center justify-content-center d-flex align-items-center">
<p class="h2 font-weight-normal">60</p>
</div>
</div>
</div>
</a>
<a href="#" class="card hoverable">
<div class="card-body p-0">
<div class="row h-100 no-gutters">
<div class="col-md-8 grey lighten-4 rounded-left">
<h5 class="font-weight-bold p-2">Header</h5>
<!-- <p class="font-weight-light text-muted mb-2 px-2">No text</p> -->
</div>
<div class="col-md-4 text-center justify-content-center d-flex align-items-center">
<p class="h2 font-weight-normal">50</p>
</div>
</div>
</div>
</a>
</div>
</div>
Please check the code differences https://i.stack.imgur.com/0Q2IX.png
Using anchor tag as it will not consider a height and width so you have to set a class in card-body using this class="card-body p-0 grey lighten-4".
Remove the class "grey lighten-4" from class="col-md-8 rounded-left pt-2" & set to class="card-body p-0 grey lighten-4"
.grey {
background-color: #f5f5f5 !important;
}
/*OR*/
.grey.lighten-4 {
background-color: #f5f5f5 !important;
}
<div class="card-deck mb-5">
<a href="#" class="card hoverable">
<div class="card-body p-0 grey lighten-4">
<div class="row mx-0">
<div class="col-md-8 rounded-left pt-2">
...
</div>
<div class="col-md-4 text-center pt-3">
...
</div>
</div>
</div>
</a>
</div>

Border is not displaying in bootstrap4? please check the code given below

This is piece of my code class="card border-primary-left shadow h-100 py-2" When i am trying to run this code then border is not displaying.
<div class="container-fluid mt-2"> <div class="col-xl-3 col-md-6 mb-4"> <div class="card border-primary-left shadow h-100 py-2"> <div class="card-body"> <div class="row no-gutters align-items-center"> <div class="col mr-2"> <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Earnings (Monthly)</div> <div class="h5 mb-0 font-weight-bold text-gray-800">$40,000</div> </div> </div> </div> </div> </div> </div>
There is no border-primary-left class in Bootstrap. Refer to the docs: https://getbootstrap.com/docs/4.4/utilities/borders/
And since the .card already has a border it would be:
card border-primary border-bottom-0 border-right-0 border-top-0

How to have a div fill the whole height of its parent column in Bootstrap

I'm looking to have the div with the red border to be the same height as its green counterpart on the right? This is in bootstrap 4!
Have tried display: flex and flex-grow, have also tried putting the border on the column (which makes the effect I'm looking for) but it then doesn't have the padding.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" >
<div class="container-fluid">
<div class="row">
<div class="col-12 col-lg-6 order-lg-1">
<div class="border border-lg border-success p-3 p-md-4 p-lg-5 text-xlarge font-weight-medium">This is an example sentence. It may go on for a couple of lines just to see what's going to happen!</div>
</div>
<div class="col-12 col-lg-6 order-lg-3">
<div class="text-xlarge text-success mt-2"><i class="icon icon-md line-height-1">check</i> Correct</div>
<p class="mb-3 mb-lg-0 text-large">Write a short explanation here</p>
</div>
<div class="col-12 col-lg-6 order-lg-2">
<div class="border border-lg border-danger p-3 p-md-4 p-lg-5 text-xlarge font-weight-medium">This is an example sentence.</div>
</div>
<div class="col-12 col-lg-6 order-lg-4">
<div class="text-xlarge text-danger mt-2"><i class="icon icon-md line-height-1">close</i> Incorrect</div>
<p class="mb-3 mb-lg-0 text-large">Write a short explanation here</p>
</div>
</div>
</div>
Here's a pen with the existing: https://codepen.io/Daggett/pen/OKJxPm
The columns are also responsive and need to stack at smaller breakpoints (hence the order-lg classes)
add d-flex to the column to use the default stretch behavior and have the same height. Also add w-100 to the element to keep it's default full width:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" >
<div class="container-fluid">
<div class="row">
<div class="col-12 col-lg-6 order-lg-1 d-flex">
<div class="border border-lg border-success p-3 p-md-4 p-lg-5 text-xlarge font-weight-medium w-100">This is an example sentence. It may go on for a couple of lines just to see what's going to happen!</div>
</div>
<div class="col-12 col-lg-6 order-lg-3">
<div class="text-xlarge text-success mt-2"><i class="icon icon-md line-height-1">check</i> Correct</div>
<p class="mb-3 mb-lg-0 text-large">Write a short explanation here</p>
</div>
<div class="col-12 col-lg-6 order-lg-2 d-flex">
<div class="border border-lg border-danger p-3 p-md-4 p-lg-5 text-xlarge font-weight-medium w-100">This is an example sentence.</div>
</div>
<div class="col-12 col-lg-6 order-lg-4">
<div class="text-xlarge text-danger mt-2"><i class="icon icon-md line-height-1">close</i> Incorrect</div>
<p class="mb-3 mb-lg-0 text-large">Write a short explanation here</p>
</div>
</div>
</div>
Bootstrap 4 rows and col-elements already have an equal height through their flex design. You only have to set the height of your inner div to 100%, to make it fill its parent space.
You can use the Bootstrap 4 h-100 class for height:100%;.
<div class="container-fluid">
<div class="row">
<div class="col-12 col-lg-6 order-lg-1">
<div class="border border-lg border-success p-3 p-md-4 p-lg-5 text-xlarge font-weight-medium">This is an example sentence. <br> It may go on for a couple of lines just to see what's going to happen!</div>
</div>
<div class="col-12 col-lg-6 order-lg-3">
<div class="text-xlarge text-success mt-2"><i class="icon icon-md line-height-1">check</i> Correct</div>
<p class="mb-3 mb-lg-0 text-large">Write a short explanation here</p>
</div>
<div class="col-12 col-lg-6 order-lg-2">
<div class="h-100 border border-lg border-danger p-3 p-md-4 p-lg-5 text-xlarge font-weight-medium">This is an example sentence.</div>
</div>
<div class="col-12 col-lg-6 order-lg-4">
<div class="text-xlarge text-danger mt-2"><i class="icon icon-md line-height-1">close</i> Incorrect</div>
<p class="mb-3 mb-lg-0 text-large">Write a short explanation here</p>
</div>
</div>

Create image grid - bootstrap4

I'm trying to create an image grid with that little space between columns equal to the image below:
The problem is that I can not make the right margin(red line), image below shows the problem:
JSfiddle: https://jsfiddle.net/castordida/0zy7qd5m/
<div class="container gridhome mt-5 mb-5 p-0">
<div class="row" style="height:469px;">
<div class="col-sm-8 h-100" style="background-color:#000;">
<span class="categoria">test</span>
<h3>TESTE</h3>
</div>
<div class="col-sm-4 h-100 p-0">
<div class="col-sm-12 h-50 p-0">
<div class="h-100 ml-1" style="background-color:#919191;">
<span class="categoria">test</span>
<h3>TESTE</h3>
</div>
</div>
<div class="col-sm-12 h-50 p-0">
<div class="h-100 ml-1 mt-1" style="background-color:#919191;">
<span class="categoria">test</span>
<h3>TESTE</h3>
</div>
</div>
</div>
</div>
<div class="row mt-1" style="height:234.5px;">
<div class="col-sm-4 h-100 p-0">
<div class="h-100" style="background-color:#919191;">
<span class="categoria">test</span>
<h3>TESTE</h3>
</div>
</div>
<div class="col-sm-4 h-100 p-0">
<div class="h-100 ml-1" style="background-color:#919191;">
<span class="categoria">test</span>
<h3>TESTE</h3>
</div>
</div>
<div class="col-sm-4 h-100 p-0">
<div class="h-100 ml-1" style="background-color:#919191;">
<span class="categoria">test</span>
<h3>TESTE</h3>
</div>
</div>
</div>
</div>
Ok it's due to the fact there is a gab between your picture at right... But the fixed height doesn't mention it...
There are many ways to correct this...
First : https://jsfiddle.net/y0x7kpza/
Add an overflow:hidden to the first .row
Second: https://jsfiddle.net/d0a52xwk/
Reaffect the height of the two div on the right in taking care of the margin-top of these elements.
.h-50-bis{
height:calc(50% - 0.125rem);
}