Reputation: 2019
I'm currently working on a website for a friend and I'm using Bootstrap 4 alpha.
Using the Cards i have three cards shown on the page and I would like that when the screen becomes mobile size to change to one card per line:
I don't want to use column but i want to use Bootstrap Cards
Example:
Normal Screen
+++ CARD 1 +++ +++ CARD 2 +++ +++ CARD 3 +++
Mobile screen
+++ CARD 1 +++
+++ CARD 2 +++
+++ CARD 3 +++
the website is: http://www.smitefr.mmo-stream.net/index.php
Example of code:
<div class="row">
<div class="card">
<img src="images/dieux/Agni.jpg" alt="Card image cap">
<h1> Agni</h1>
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div><div class="card">
<img src="images/dieux/AhMuzenCab.jpg" alt="Card image cap">
<h1> Ah Muzen Cab</h1>
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div><div class="card">
<img src="images/dieux/AhPuch.jpg" alt="Card image cap">
<h1> Ah Puch</h1>
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div>
</div>
Example of css:
.card {
float: left;
width: 33.333%;
padding: .75rem;
margin-bottom: 2rem;
border: 0;
}
.card > img {
margin-bottom: .75rem;
display: block;
width: 80%;
height: auto;
margin-left: auto;
margin-right: auto;
}
.card-text {
font-size: 85%;
}
Upvotes: 6
Views: 17339
Reputation: 1433
After several hours of exploration, the below worked for me.
If you want a responsive card-deck, use the visibility utils to force a wrap every X columns on different viewport width(breakpoints)...
Bootstrap 4 responsive card-deck (v 4.1)
More details available in the below link.
Bootstrap 4 card-deck with number of columns based on viewport
Upvotes: 0
Reputation: 167172
You can do something like this:
<!-- Columns start at full width on mobile and bump up to 33.3% wide on desktop -->
<div class="container">
<div class="row">
<div class="col-sm col-xs-12">One</div>
<div class="col-sm col-xs-12">Two</div>
<div class="col-sm col-xs-12">Three</div>
</div>
</div>
Updated with the cards:
<div class="container">
<div class="row">
<div class="col-sm col-xs-12">
<div class="card">
<img src="//placehold.it/100?text=Agni.jpg" alt="Card image cap" />
<h1> Agni</h1>
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div>
</div>
<div class="col-sm col-xs-12">
<div class="card">
<img src="//placehold.it/100?text=AhMuzenCab.jpg" alt="Card image cap" />
<h1> Ah Muzen Cab</h1>
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div>
</div>
<div class="col-sm col-xs-12">
<div class="card">
<img src="//placehold.it/100?text=AhPuch.jpg" alt="Card image cap" />
<h1> Ah Puch</h1>
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div>
</div>
</div>
</div>
Snippet
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />
<div class="container">
<div class="row">
<div class="col-sm col-xs-12">
<div class="card">
<img src="//placehold.it/100?text=Agni.jpg" alt="Card image cap" />
<h1> Agni</h1>
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div>
</div>
<div class="col-sm col-xs-12">
<div class="card">
<img src="//placehold.it/100?text=AhMuzenCab.jpg" alt="Card image cap" />
<h1> Ah Muzen Cab</h1>
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div>
</div>
<div class="col-sm col-xs-12">
<div class="card">
<img src="//placehold.it/100?text=AhPuch.jpg" alt="Card image cap" />
<h1> Ah Puch</h1>
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div>
</div>
</div>
</div>
See the responsive demo of above code in JSBin.
Preview
Desktop View
Mobile View
Upvotes: 8