Bootstrap 4 Grid issue in small devices - flexbox

My code is given below
<div class="row align-items-center">
<div class="col-12 col-xl-6 col-lg-6 col-md-12 col-sm-12">
One of three columns
</div>
<div class="col-12 col-xl-6 col-lg-6 col-md-12 col-sm-12">
One of three columns
</div>
</div>
CSS look like below
.row {
height: calc(70vh - 60px);
}
When I check-in mobile or small device grid item put some space in upper side and lower side. screenshot attached below
you can see space. I want to make div without space.
How can I?

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div style="height: 200px;background-color: sandybrown;" class="d-flex align-items-center justify-content-center">
<div class="row no-gutters d-flex bg-primary">
<div class="col-12 col-md-6 bg-info">on small 12-cols and medium or above 6-cols</div>
<div class="col-12 col-md-6 bg-warning">on small 12-cols and medium or above 6-cols</div>
</div>
</div>
if you want no padding, no margin only on small screen, you can use media query in scss
#media (max-width: 576px) {
margin: 0px; padding: 0px
}

Related

Can I alter the way Bootstrap places columns?

I am looking for a way to make a row with 8 col-md-6 divs display in a different way than usual.
How bootstrap normally does it:
How I want it:
The number columns is dynamic so it can exceed 20 for example and be a uneven number.
Code:
<div class="row">
{foreach from=$item.Opties|default:array() name=optie item=optie key=key}
<div class="col-md-6">
test {$optie#iteration} (normally there is more code in here)
</div>
{/foreach}
</div>
I have tried:
order-md-* but for this solution i need to add css since it might exceed 12 which i'd rather not.
Having just 2x .col-md-6 and the foreach in there but its a bad solution. since then I have big piece of html twice.
If you can't change the markup structure there's no simple way.
One option is to use flex-column but there is no way to set the number of divs per column so you'd have to use max-height...
#media(min-width:768px) {
.mh {
flex-direction: column;
max-height:140px;
}
}
Another option is to use CSS columns which order from top to bottom instead of left to right.
.row.columns {
column-count: 2;
column-gap: .1rem;
display:block;
}
.columns > .col-md-6 {
display: inline-block;
width: 100%;
max-width: 100%;
}
The last option is to use flexbox ordering for the specific positions...
<div class="row">
<div class="col-md-6 order-1">
<div class="border p-1">1</div>
</div>
<div class="col-md-6 order-3">
<div class="border p-1">2</div>
</div>
<div class="col-md-6 order-5">
<div class="border p-1">3</div>
</div>
<div class="col-md-6 order-7">
<div class="border p-1">4</div>
</div>
<div class="col-md-6 order-2">
<div class="border p-1">5</div>
</div>
<div class="col-md-6 order-5">
<div class="border p-1">6</div>
</div>
<div class="col-md-6 order-4">
<div class="border p-1">7</div>
</div>
<div class="col-md-6 order-8">
<div class="border p-1">8</div>
</div>
</div>
Demo: https://www.codeply.com/go/IczuqP9l7K

Bootstrap stacked cards

I have a flexbox column with three bootstrap 4 cards. when I resize the container the first one get taller or shorter because of its responsive design. What I want is to keep the whole container height constant and shrink and grow the middle card. Here is my code:
HTML
<div >
<div class="cards">
<div class="card">
<div class="row">
<div class="col-md-6">
1234
</div>
<div class="col-md-6">
5678
</div>
</div>
</div><!-- /card-one -->
<div class="card">
<p>content for card two</p>
</div><!-- /card-two -->
<div class="card">
<p>content for card three</p>
</div><!-- /card-three -->
</div>
CSS:
.cards {
display: flex;
flex-flow: column;
justify-content: space-between;
}
Fiddle:
Sample
Thanks

flex-column of bootstrap fills out full width, how to not stretch to full width?

see here:
https://getbootstrap.com/docs/4.0/utilities/flex/#direction
items stretch to full width, but that is not really my desired outcome.
I want the items to keep their original size
what is the proper way of doing that?
Wrap the flex-column element with a col-auto element so that it takes as much space as it needs.
.bd-highlight {
background: #eee;
border: 1px solid
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-auto">
<div class="d-flex flex-column bg-highlight mb-3">
<div class="p-2 bd-highlight">Flex item 1</div>
<div class="p-2 bd-highlight">Flex item 2</div>
<div class="p-2 bd-highlight">Flex item 3</div>
</div>
</div>
</div>
You may use a container also.
Even better, use a d-flex element to wrap the flex-column element. But if you do, remove the d-flex and flex-column classes from the element itself and instead use w-auto.
.bd-highlight {
background: #eee;
border: 1px solid
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="d-flex">
<div class="w-auto bg-highlight mb-3">
<div class="p-2 bd-highlight">Flex item 1</div>
<div class="p-2 bd-highlight">Flex item 2</div>
<div class="p-2 bd-highlight">Flex item 3</div>
</div>
</div>

Bootstrap 4 align-items-bottom inside div flexbox

this is simple. I'm trying to align-items-bottom a gear svg image to the bottom center of a div. However, it always keeps at the top of the div.
I tried both align-items-center and also align-bottom options.
What happens
How it should be
.gear {
height: 50px;
}
.banner {
height: 70px;
}
<footer>
<div class="container-fluid orange-bg banner d-flex justify-content-center align-items-bottom">
<img class="gear d-flex" src="/assets/gear.svg">
</div>
</footer>
There is no align-items-bottom class. The class name is align-items-end..
<div class="container-fluid orange-bg banner d-flex justify-content-center align-items-end">
<img class="gear d-flex" src="//placehold.it/300x70">
</div>
https://www.codeply.com/go/ub6hNpd9TL
Rows and column are your friends in Bootstrap.
So, create a pair, put your image/SVG inside, apply the class d-flex to the column and mt-auto (margin-top:auto) to the image.
Click the "run code snippet" button below:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<footer>
<div class="container-fluid bg-warning banner d-flex justify-content-center">
<div class="row" style="height: 60px;">
<div class="col d-flex">
<img class="gear mt-auto" src="https://placehold.it/30">
</div>
</div>
</div>
</footer>

Aligning items within a Bootstrap 4 .card using Flexbox

I'm using Bootstrap 4, and have a div with the card class on it, which has a fixed height. This is what I'm trying to get:
The code I'm using is
<div class="card">
<div class="card-block d-flex flex-column">
<h2 class="card-title h4 align-self-start">Top Left</h2>
<div class="align-self-center">
Middle Middle
</div>
<aside class="align-self-end">Bottom Right</aside>
</div>
</div>
but the lines are all squashed together, presumably because the card-block is not expanding to the full height of the card.
Is there a way to get the card-block to fill the card, or otherwise get this to display correctly?
You can use justify-content-between on the card-block..
<div class="card">
<div class="card-block d-flex flex-column">
<h2 class="card-title h6 align-self-start flex-grow d-flex">Top Left<br>Top Left</h2>
<div class="align-self-center flex-grow d-flex">
Middle Middle
</div>
<aside class="align-self-end flex-grow d-flex align-items-end">Bottom Right</aside>
</div>
</div>
.flex-grow {
flex: 1 0 0;
}
Demo: https://www.codeply.com/go/5dIgA0ul2q
Update 2018 Bootstrap 4 (stable)
card-block is now card-body

Resources