Reorder bootstrap column on click function - html

I want to switch columns order using bootstrap and jQuery on click.
I've done this for the left button, but it doesn't work:
$("#left").on("click",
function() {
$("#A").removeClass('order-1').addClass('order-2');
$("#B").removeClass('order-2').addClass('order-1');
console.log("1 done")
},
function() {
$("#A").removeClass('order-2').addClass('order-1');
$("#B").removeClass('order-1').addClass('order-2');
}
);
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="arrow position-absolute top-50 start-0 translate-middle-y ps-2" id="left">left</div>
<div class="arrow position-absolute top-50 end-0 translate-middle-y pe-2" id="right">right</div>
<div class="col-6 bg-success d-flex align-items-end order-1" id="A">one
</div>
<div class="col-6 bg-primary d-flex align-items-end order-2" id="B">two
</div>

Here you go...
There are a few problems.
You tagged this questions as bootstrap-4, but used bootstrap-5 in your code.
Bootstrap classes order-1 and order-2 were not even working because you need to wrap col classes with a row class.
Use jQuery toggleClass to change classes.
See the snippet below.
$(document).ready(function() {
$(".col-6").click(function() {
$("#A").toggleClass("order-1 order-2");
$("#B").toggleClass("order-2 order-1");
});
});
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="row">
<div class="col-6 bg-success d-flex align-items-end order-1" id="A">one</div>
<div class="col-6 bg-primary d-flex align-items-end order-2" id="B">two</div>
</div>

Related

Bootstrap Responsive Grid System

I am making a section that contain some text but i need the text in the right half of the section and on the left there is a background image for the section, so i made col-md-4 for the unused half because i don't wanna hide the background image and col-md-8 to the text, how to hide the col-md-4 section on the small screen and let the col-md-8 cover the whole section? iam using bootstrap 5
the code:
<!-- Bootstrap 4.1.x/Twitter Library -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Body -->
<div class="header-main row">
<div class="col-md-4"></div>
<div class="col-md-8 text-center d-flex flex-column justify-content-center align-items center">
<h1 class="first-font">MOBI TECH</h1>
<h2 class="second-font my-4">THE CHEAPEST PRICE<br>THE BEST QUALITY</h2>
<a class="btn-light-outline first-font px-5 py-2 rounded-pill">SHOP NOW</a>
</div>
</div>
the output on desktop:
the output on phones:
To hide element on particluar screen breakpoint use .d-sm-none .d-md-block
<!-- Bootstrap 4.1.x/Twitter Library -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Body -->
<div class="header-main row">
<div class="col-md-4 .d-sm-none .d-md-block"></div>
<div class="col-md-8 col-sm-12 text-center d-flex flex-column justify-content-center align-items center">
<h1 class="first-font">MOBI TECH</h1>
<h2 class="second-font my-4">THE CHEAPEST PRICE<br>THE BEST QUALITY</h2>
<a class="btn-light-outline first-font px-5 py-2 rounded-pill">SHOP NOW</a>
</div>
</div>
this will leave layout as you defined for md screens and hide firs div and make second div 12 cols wide on sm screens.

Bootstrap-4 justify-content-around not working for flex-column

I'm using bootstrap-4, I don't understand why justify-content-around works for flex-row and not flex-column?
I applied flex-column justify-content-around for the div.item2 and it's not working. But when I use flex-row justify-content-around for div.main it works!
How can i make it work?
I have used css only for color purpose. Here is my code:
.main{background-color:pink;}
.item1{background-color:red;}
.a{background-color:green;}
.b{background-color:yellow;}
.c{background-color:blue;}
<head>
<!-- CSS Stylesheets -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" href="css/styles.css">
<!-- Bootstrap Scripts -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
</head>
<body>
<div class="main d-flex flex-row justify-content-around bd-highlight">
<div class="item1 d-flex p-2 bd-highlight">Flex item 1</div>
<div class="item2 d-flex flex-column justify-content-around bd-highlight">
<div class="a p-2 bd-highlight">Flex item 2.1</div>
<div class="b p-2 bd-highlight">
<h2 class="price-text">Flex item 2.2</h2>
<p>fermentum iaculis eu</p>
<p>lectus vestibulum mattis</p>
<p>cursus in hac</p>
<button class="btn btn-lg btn-block btn-outline-dark" type="button">Sign Up</button>
</div>
<div class="c p-2 bd-highlight">Flex item 2.3</div>
</div>
</div>
</body>
The justify-content property aligns the flexible container's items
when the items do not use all available space on the main-axis
https://www.w3schools.com/cssref/css3_pr_justify-content.asp
In your case the items use all available space (The height of .item2 = the height of the content inside = No available space = No visual change).
Very simple code example to show this: add some height to .item2 (600px for example):
.main{background-color:pink;}
.item1{background-color:red;}
.a{background-color:green;}
.b{background-color:yellow;}
.c{background-color:blue;}
aside{
border: 5px solid green;
height: 600px;
}
#stroke{
border: 5px solid red;
}
<head>
<!-- CSS Stylesheets -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" href="css/styles.css">
<!-- Bootstrap Scripts -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
</head>
<body>
<div class="main d-flex flex-row justify-content-around">
<main class="item1 d-flex p-2 bd-highlight">Flex item 1</main>
<aside class="item2 d-flex flex-column justify-content-around">
<div class="a p-2 bd-highlight">Flex item 2.1</div>
<div id="stroke" class="b p-2 bd-highlight">
<h2 class="price-text">Flex item 2.2</h2>
<p>Nested item 1</p>
<p>Nested item 2</p>
<p>Nested item 3</p>
<button class="btn btn-lg btn-block btn-outline-dark" type="button">Sign Up</button>
</div>
<div class="c p-2 bd-highlight">Flex item 2.3</div>
</aside>
</>
</body>

Why the Chrome cannot display the web page correctly when the windows is minimized?

I am trying to build custom video control.
Here is my code:
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<style>
video {
transform: scale(-1, 1);
object-fit: cover;
}
</style>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
</head>
<body class="p-1">
<div class="border-top border-primary container-fluid">
<div class="h-25 row">
<div class="border-left border-bottom border-primary col-6 d-flex flex-column p-1" style="box-sizing:border-box">
<div class="bg-primary h-75 text-white">
sdfsfd
</div>
<div class="bg-secondary h-25 text-danger">
9080
</div>
</div>
<div class="border-left border-bottom border-right border-primary col-6 d-flex flex-column p-1">
<video id="remoteView" autoplay muted>
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
</video>
</div>
</div>
<div class="row">
<div class="align-items-center border-left border-bottom border-right border-primary col-12 d-flex flex-row justify-content-center p-0">
<div class="btn-group-toggle d-flex justify-content-center p-1">
<button class="btn-sm btn btn-lg btn-success">A</button>
</div>
<div class="btn-group-toggle d-flex justify-content-center p-1">
<button class="btn-sm btn btn-lg btn-success">B</button>
</div>
<div class="btn-group-toggle d-flex justify-content-center p-1">
<button class="btn-sm btn btn-lg btn-success">C</button>
</div>
</div>
</div>
</div>
</body>
</html>
The upper left cell cannot be displayed correctly when the Chrome browser window is minimized.
However, in the Firefox browser, the problem does not exist.
How can I fix it?
video { height: 100vh; min-height: 100%; }
You can get more details about video fullscreen, following this How to - Fullscreen Video
Try pressing Ctrl+Shift+R.
In most cases it will fix the problem.

Bootstrap 4 change col position on differents sizes

I'm trying to display 3 cols in a different order and position, on display bigger or smaller then the "md" breakpoint.
On > md layout, the col "A" "B" should be one above the other, while the col "C" should be on the right of both of them.
On < md layout the col "A" should be 100% large, while the "B" and "C" should be on the same row.
I tried so far most of combination of bootsrap classes (for row and col), but haven't figured out how to reach this behaviour.
Attacched an image to better explain the question.
Using Bootstrap 4 do something like this...
.border-div {
margin: 5px;
border: 4px solid;
min-height: 100px;
}
.c-div-block {
max-width: calc(100% - 10px);
max-height: calc(100% - 25px);
}
.border-div.normal-span {
line-height: 100px;
}
.border-div.expanded-span {
line-height: 200px;
}
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" />
<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.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
crossorigin="anonymous"></script>
</head>
<body>
<div class="container-fluid my-5">
<div class="row no-gutters position-relative py-2">
<div class="col-12 col-md-9 order-first order-md-first">
<div class="border-div border-dark text-center normal-span">A</div>
</div>
<div class="col-6 col-md-9 order-2 order-md-last">
<div class="border-div border-danger text-center normal-span">B</div>
</div>
<div class="position-absolute offset-md-9 col-md-3 order-md-2 h-100 d-none d-md-block">
<div class="border-div border-success h-100 c-div-block text-center expanded-span">C</div>
</div>
<div class="col-6 order-last d-block d-md-none">
<div class="border-div border-success text-center normal-span">C</div>
</div>
</div>
</div>
</body>
</html>
Note: div width and height may differ as per your requirement, so do the adjustment on you own.
Hope it will help many one.

Bootstrap 4 border class not working for top, right

I am trying to give border to div with bootstrap 4 border. With only border property it is appearing weird while with other properties no border is showing up. Please find the code snippet below.
I have tried with the beta 2 version also.
Let me know if I am missing something.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home</title>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
</head>
<body>
<!-- Just created a contianer to test the border class -->
<div class="container">
<div class="text-center">
<h1> Testing bootstrap 4</h1>
</div>
<div class="row mt-2">
<div class="col-12">
<!-- Testing span with class border -->
<span class="border">
<div class="text-primary">Testing Bootsrap 4 Border </div>
</span>
</div>
</div>
<div class="row mt-2">
<div class="col-12">
<span class="border-0">Testing Bootsrap 4 Border 0</span>
</div>
</div>
<div class="row mt-2">
<div class="col-12">
<span class="border-top-0">Testing Bootsrap 4 Border top 0</span>
</div>
</div>
<div class="row mt-2">
<div class="col-12">
<span class="border-right-0">Testing Bootsrap 4 Border right 0</span>
</div>
</div>
<div class="row mt-2">
<div class="col-sm-12">
<span class="border border-light">testing border light</span>
</div>
<div class="col-sm-12"> col 2</div>
</div>
</div>
</body>
</html>
For bootstrap border to work, you have to add the border class. So for example, when you write <span class="border-right-0"> It is stating that no border should be to the right. You haven't stated a border to begin with though so no border is going to show. What you need to do is <span class="border border-right-0">.
It's the Subtractive border so first, you will need a border so you need to include the border class first.
<span class="border border-top-0"></span>
To see it in more effect try this:
<span class="border border-top-0 p-2 border-primary">Border</span>
Using contextual classes and padding utilities you can easily get the difference.
Hey you just need to add some classes for showing the border i.e. border border-primary, border border-secondary etc.
And class "border border-0" means no border.
In class="border border-light", "border-light" is another contextual border color.
Below are useful classes:
A list of contextual border color you can use the below classes:
border-primary
border-secondary
border-white
border-dark
border-light
border-info
border-warning
border-danger
border-success
If you want to get easier then try https://www.w3schools.com/bootstrap4/bootstrap_utilities.asp or https://v4-alpha.getbootstrap.com/utilities/borders/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<title>Home</title>
</head>
<body>
<!-- Just created a contianer to test the border class -->
<div class="container">
<div class="text-center">
<h1> Testing bootstrap 4</h1>
</div>
<div class="row mt-2">
<div class="col-12">
<!-- Testing span with class border -->
<span class="border">
<div class="text-primary">Testing Bootsrap 4 Border </div>
</span>
</div>
</div>
<div class="row mt-2">
<div class="col-12">
<span class="border-0 border border-primary">Testing Bootsrap 4 Border 0</span>
</div>
</div>
<div class="row mt-2">
<div class="col-12">
<span class="border border-primary border-top-0">Testing Bootsrap 4 Border top 0</span>
</div>
</div>
<div class="row mt-2">
<div class="col-12">
<span class="border border-danger border-right-0">Testing Bootsrap 4 Border right 0</span>
</div>
</div>
<div class="row mt-2">
<div class="col-sm-12">
<span class="border border-light">testing border light</span>
</div>
<div class="col-sm-12"> col 2</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
</body>
</html>