Bootstrap display property gap fix - html

I have this div row that I would like to have adjusted when the window size changes.
<div class="row">
<div class="col-md-12 d-block d-sm-none d-xs-none text-center">
Login
<span class="or-spacer my-auto">or</span>
Register
<br>
<p>to claim this coupon</p>
</div>
<div class="col-md-12 text-left d-none d-md-block d-lg-block d-xl-block">
Login
<span class="or-spacer my-auto">or</span>
Register
<span class="or-spacer my-auto">to claim this coupon</span>
</div>
</div>
I followed the classes in this bootstrap page: https://getbootstrap.com/docs/4.0/utilities/display/
the top div displays on size sm and below and the bottom one shows on size md and above.
The problem is there is a small gap in between md and sm that displays neither of the two. The Login and Register buttons disappear.
md+
between md and sm (no display)
sm-
What can be changed for the no display in between md and sm?

There is no gap between sm and md
sm ranges till 767px while md starts from 768px
Try this :
<div class="row">
<div class="d-none d-md-block">
visible for md and above
</div>
<div class="d-block d-md-none">
visible for sm and below
</div>
</div>

You just needed to change d-sm-none to d-md-none in your sm block:
<div class="row">
<div class="col-md-12 d-block d-md-none d-xs-none text-center">
Login
<span class="or-spacer my-auto">or</span>
Register
<br>
<p>to claim this coupon</p>
</div>
<div class="col-md-12 text-left d-none d-md-block d-lg-block d-xl-block">
Login
<span class="or-spacer my-auto">or</span>
Register
<span class="or-spacer my-auto">to claim this coupon</span>
</div>
</div>

Related

Bootstrap v5: Column elements become farther apart on smaller screens?

On my widescreen monitor, my cover page looks like this (which is how I want it to look):
But on my smaller screen laptop, the words and the buttons (which are each in two separate columns) get spread out and my cover page looks like this:
I've tried several things but I can't seem to get them to stick together on smaller screens. Here is the relevant HTML code:
HTML:
<div class="container h-100">
<div class="row d-flex h-100 justify-content-center align-items-center g-0">
<div class="col-sm-6">
<div class="row">
<h1 class="title">transfer your</h1>
</div>
<div class="row">
<h1 class="title">music</h1>
</div>
<div class="row">
<h2 class="subtitle">between Spotify & YouTube</h2>
</div>
</div>
<div class="col-sm-4">
<div class="row mb-3">
<a class="btn" id="sp-to-yt" href="#" role="button">
</a>
</div>
<div class="row">
<a class="btn" id="yt-to-sp" href="#" role="button">
</a>
</div>
</div>
</div>
</div>
It's based on a percentage width. You can use the responsive classes to manage each screen size.
For small screens use <div class="col-sm-6"></div> which will display half-width on small screens. You can use multiple responsive classes like so...
<div class="col-sm-6 col-md-8 col-lg-3 col-xl-4"></div>
The responsive elements can be remembered as sm = small, md = medium, lg = large, etc, and will control each breakpoints div widths. Remember the max number of columns by default is 12.
Also, in your row.. <div class="row d-flex h-100 justify-content-center align-items-center g-0"> you don't need to define the display flex as .row is already a display flex class.

bootstrap sm resize not brakeing

So this is my HTML Code. (bootstrap css is in head included)
According to Bootstrap it should take for each col div on small screens 12 which is basically the full screen.
also it should hide the img with the .d-sm-none .d-md-block
but when iam doing the resize in chrome tools its not going well.
google coulndt help me so far. also tried removing flex class , dosent changed a thing
<body cz-shortcut-listen="true">
<div class="container-fluid">
<div class="row d-flex flex-wrap">
<div class="col-sm-12 col-md-6 col-lg-3 ">
<div class="card" style="width: 18rem;">
<img class="card-img-top d-sm-none d-md-block" src="img/1.jpg" alt="Tower">
<div class="card-body">
<h5 class="card-title">Tower</h5>
<p class="card-text">City: dubay Zip-Code 4993
<br>
</p><p>Created: 1.2.2015, 05:40:00
</p>
</div>
</div>
</div>
<div class="col-sm-12 col-md-6 col-lg-3 ">
<div class="card" style="width: 18rem;">
<img class="card-img-top d-sm-none d-md-block" src="img/1.jpg" alt="Palme">
<div class="card-body">
<h5 class="card-title">Palme</h5>
<p class="card-text">City: Dubai Zip-Code 333
<br>
</p><p>Created: 1.2.2011, 05:40:00
</p>
</div>
</div>
</div>
<div class="col-sm-12 col-md-6 col-lg-3">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="img/2.jpg" alt="Mcdonald">
<div class="card-body">
<h5 class="card-title">Mcdonald fastfood</h5>
<p class="card-text">City: melbourn Zip-Code 4544
<br>
</p><p>
<label>Phone, Web</label>
<br>
+66 4895643312
<br>
www.getfat.com
</p><p>Created: 2.3.2020, 04:30:00
</p>
</div></div>
</div>
<div class="col-sm-12 col-md-6 col-lg-3">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="img/2.jpg" alt="Burgerkin">
<div class="card-body">
<h5 class="card-title">Burgerkin fastfood</h5>
<p class="card-text">City: Switzerlan Zip-Code 4334
<br>
</p><p>
<label>Phone, Web</label>
<br>
+66 443543512
<br>
www.getfatter.com
</p><p>Created: 2.3.2011, 04:30:00
</p>
</div></div>
</div>
<div class="col-sm-12 col-md-6 col-lg-3">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="img/3.jpg" alt="Eating Burger">
<div class="card-body">
<h5 class="card-title">Eating Burger</h5>
<p class="card-text">City: burgertown Zip-Code 4234
<br>
<label> Event Infos </label>
</p><ul>
<li>14. June. 2100</li>
<li>3 o clock</li>
<li>56</li>
<li>www.event.com</li>
</ul>
<p>Created: 1.2.2019, 03:25:00
</p>
</div></div>
</div>
<div class="col-sm-12 col-md-6 col-lg-3">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="img/3.jpg" alt="Sky diving">
<div class="card-body">
<h5 class="card-title">Sky diving</h5>
<p class="card-text">City: skytown Zip-Code 4666
<br>
<label> Event Infos </label>
</p><ul>
<li>14. June. 2000</li>
<li>5 o clock</li>
<li>560</li>
<li>www.eve222nt.com</li>
</ul>
<p>Created: 1.2.2011, 03:25:00
</p>
</div></div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
The d-sm-none is functioning correctly. You have it on the img tag and therefore in the breakpoints referenced in bootstraps documentation here you can see the sm breakpoint is actually for landscape phones and as such will only hide the img from 576px to 768px. If you were trying to target this on a regular vertical orientation on a phone than you can replace where you have d-sm-none d-md-block and replace it with .d-none .d-sm-block like so:
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-3 ">
<div class="card">
<img class="card-img-top d-none d-sm-block" src="img/1.jpg" alt="Palme">
<div class="card-body">
<h5 class="card-title">Palme</h5>
<p class="card-text">
City: Dubai Zip-Code 333
<br>
</p>
<p>HIDE ME</p>
<p>
Created: 1.2.2011, 05:40:00
</p>
</div>
</div>
</div>
</div>
You can see this here in dev tools when i set it to 576px and you see the img is visible with the PALME section saying HIDE ME which i added to mark the card you have the img you want to hide on.
And then here when we go to 575px you can see it disappear like its supposed to:
As far as your column div problem I am not sure I understand what you are asking but I do see what is wrong with your code. In bootstrap you must have the class container which you do and then inside goes a row (on each row there are 12 columns). Once a row is filled up you must create another row to put your content into which again can hold up to 12 columns.
How you have the code currently is 1 row inside of a container and then your cards which all have col 12 on it. Below is a demo of what I assume you were trying to do which is to have the cards span the whole screen from a small screen up till when you want them to take up half the screen which I see from you putting col-md-6.
I did the demo by removing the flex classes and also by removing the width of the card that you had set as 18rem. It now spans the whole screen as I also added in col-xs-12 to be full screen on vertical orientation phones since the lowest you had on your cards was col-sm-12 which as I said above only is the width of landscape orientation for phones.
Demo:https://jsfiddle.net/atcvmqLx/
Explanation: Youll see on there that even though the images arent attached that the cards themselves expand to be full screen until it hits the col-md-6 breakpoint # 768px.
Let me know if you have any questions!

Visualizing Bootstrap 4.x Grid Breakpoints during development

If you use grid system in Bootstrap 4.x, it can be useful to know exactly which grid breakpoint corresponds to the current viewport width.
You can accomplish this by adding the following HTML at the top of your page. When you resize the browser window, the corresponding size will be displayed.
<div class="d-block d-sm-none">
<b>Extra Small</b> <576px
</div>
<div class="d-none d-sm-block d-md-none">
<b>Small</b> ≥576px
</div>
<div class="d-none d-md-block d-lg-none">
<b>Medium</b> ≥768px
</div>
<div class="d-none d-lg-block d-xl-none">
<b>Large</b> ≥992px
</div>
<div class="d-none d-xl-block">
<b>Extra Large</b> ≥1200px
</div>
When you resize your browser window, you can see what the current grid breakpoint is. Remeber to remove this when development is done.

Bootstrap - move the next <div> on top of previous on medium and small devices

I have the following div in Bootstrap:
<div class="card-header py-md-0 py-lg-0 py-xl-0 pl-0 pr-0">
<div class="d-flex justify-content-between align-items-center">
<div class="h5 mb-0">Text text</div>
<div class="text-right">
<div class="actions">
<a href="#" class="action-item"><i
class="far fa-heart mr-1"></i>
50</a>
<a href="#" class="action-item"><i class="far fa-eye mr-1"></i>
250</a>
</div>
</div>
</div>
<p class="font-size-1">Text text text text text
</p>
</div>
On medium and small devices I would like that the second div having class="actions" to go on top of the first and aligned left.
I have tried so far to do something like below but it doesn't work. Something I'm missing:
#media only screen and (max-width: 960px) {
.col-xs-12 {
display: flex;
flex-direction: column-reverse;
}
}
Some tips? Thanks
Assuming you're using Bootstrap 4:
Bootstrap is built for mobile-first, so the easiest solution is to layout the code in order from the .sm view, which would be the div you want first as the first one in that entire .row.
Here is the section in Bootstrap 4 covering this: https://getbootstrap.com/docs/4.4/layout/grid/#order-classes
You'll have to add .order-lg-2 to the div you want to show first on sm and md screens (remember, mobile first). You can also use things Bootstrap classes like .justify-content-[sm, md, lg]-[start, center, between, end, around] to set its position. You may also have to add .d-flex to the second div (that's how it all worked for me in a project).
Here is an example of what I've used that worked (these sections were side-by-side on lg+, so your column sizes might need to be adjusted):
<div class="container">
<div class="row">
<div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 order-lg-2 justify-content-center justify-content-sm-start"> <!-- shows first on sm/md, 2nd on lg -->
<!-- your code -->
</div>
<div class="col-xl-8 col-lg-8 col-md-12 col-sm-12 order-lg-1 justify-content-center justify-content-md-start"> <!-- shows 2nd on sm/md, 1st on lg -->
<!-- more code -->
</div>
</div>
</div>
Here is a quick CodePen I set up to show you how it works:
Codepen

Navbar doubles in height on resizing

I've (almost) created a responsive navbar however between phone screen size and full window size the bar doubles in height. I've tried a bunch of bootstrap classes without success. This is the full screen format (correct):
And this is after reducing the browser window size (incorrect):
If anyone could tell me what is causing this it would be really helpful.
<!-- header area start -->
<header id="header">
<div class="header-area">
<div class="container">
<div class="row d-flex align-items-center justify-content-between">
<!-- <div class="menu-area"> -->
<div class="">
<div class="logo px-4">
<h3 style="color: #ffffff;"><a style="color: #ffffff;">Header</a></h3>
</div>
</div>
<div class="col-lg-9 d-none d-md-block">
<div class="main-menu">
...
</div>
</div>
<div class="col-md-12 col-12 d-none d-sm-block d-md-none d-block d-sm-none">
<div class="mobile_menu"></div>
</div>
</div>
</div>
</div>
</div>
</header>
<!-- header area end -->
.header-area{position:fixed;left:0;top:0;width:100%;z-index:998;background-color:#27ae60}
.menu-area{display:flex;align-items:center}
.logo h3{font-family:'Lato',sans-serif;color:#fff}
.logo a{display:inline-block;font-family:'Lato',sans-serif;color:#fff;font-size:18px}
From what I know every immediate child of the row class should typically be a col so that all children equals 12 and assigns the width accordingly. When you say col-lg-9 that means that while we are in a large viewport this div should take up 9/12 width. When it is a viewport below large (lg) we will be the full 12 wide and start to stack. So for example
large
| col-lg-2 | col-lg-6 | col-lg-4 |
medium and small
| col-lg-2 |
| col-lg-6 |
| col-lg-4 |
you can fine tune this with md and sm and customise what happens when it reaches those viewports. I don't think it's a great explanation but I hope it helped. You should try to keep your classes equalling 12 and using the same size lg or md or sm across all of them.