issue with button in html bootstrap - html

I'm following this video tutorial https://www.youtube.com/watch?v=36jRXMsIFuA
I am using bootstrap 5.0.0 beta 1
My code is following:
<header>
<div class="container">
<div class="row">
<div class="col-md-4 col-sm-12 col-12 bg-light">
<div class="btn-group">
<button class="btn border dropdown-toggle my-md-4 my-2" data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false">AUD</button>
<div class="dropdown-menu">
USD
</div>
</div>
</div>
<div class="col-md-4 col-12 text-center bg-dark"></div>
<h2 class="my-md-3 site-title">Online Store</h2>
<div class="col-md-4 col-12 text-right bg-danger">
<p class="my-md-4 header-links">
Sign In
Create an Account
</p>
</div>
</div>
</div>
</header>
And it looks like this, and when I click the button there is no dropdown. Layout is messed up as well.
my website
Compared to tutorial:
tutorial picture

The tutorial's using Bootstrap 4.3.1, the 4th version rather than the newest 5.0. If you switch to v4, your dropdown would works. Since a major update of a framework (increase of the first version number) is always not compatible to below versions.
About the layout, there's a mistake in your code. You need to put your <h2> tag within the tag with a background color and a style, the above <div> tag.
So, change the lines below:
<div class="col-md-4 col-12 text-center bg-dark"></div>
<h2 class="my-md-3 site-title">Online Store</h2>
To:
<div class="col-md-4 col-12 text-center bg-dark">
<h2 class="my-md-3 site-title">Online Store</h2>
</div>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<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>
<header>
<div class="container">
<div class="row">
<div class="col-md-4 col-sm-12 col-12 bg-light">
<div class="btn-group">
<button class="btn border dropdown-toggle my-md-4 my-2" data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false">AUD</button>
<div class="dropdown-menu">
USD
</div>
</div>
</div>
<div class="col-md-4 col-12 text-center bg-dark">
<h2 class="my-md-3 site-title">Online Store</h2>
</div>
<div class="col-md-4 col-12 text-right bg-danger">
<p class="my-md-4 header-links">
Sign In
Create an Account
</p>
</div>
</div>
</div>
</header>

Related

Gif does not appear when clicking button

This is the code :
<button class="fun" data-toggle="collapse" data-target="emoji">Click For Fun!</button>
<div id="emoji" class="collapse">
<div class="container-fluid padding">
<div class="row text-center">
<div class="col-sm-6 col-md-3">
<img class="gif" src="img/gif/panda.gif">
</div>
</div>
</div>
</div>
The button has the data target set to "emoji" but when I click the button nothing happens.
data-target="#emoji" will solve your problem.
<button class="fun" data-toggle="collapse" data-target="#emoji">Click For Fun!</button>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<button class="fun" data-toggle="collapse" data-target="#emoji">Click For Fun!</button>
<div id="emoji" class="collapse">
<div class="container-fluid padding">
<div class="row text-center">
<div class="col-sm-6 col-md-3">
<img class="gif" src="https://media0.giphy.com/media/Tia2InBEWaQgckP3UG/source.gif">
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

Responsive image won't follow col-sm-12

In small screens, my responsive image gets smaller till it disappears, even tho I specified that I wanted the images to be on top of each other on small screens, hence my col-md-6 col-sm-12. Any idea what's wrong with my code ?
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<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.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="row">
<div class="col-md-12 d-flex">
<div class="media block-6 services d-flex align-items-center">
<div class="col-md-6 col-sm-12 d-flex">
<div class="media-body pl-4 pl-md-0 pr-md-4 text-md-left">
<h3 class="heading">Title</h3>
<p class="mb-0">Description</p>
</div>
</div>
<div class="col-md-6 col-sm-12 d-flex">
<div class="d-flex align-items-center justify-content-center">
<img class="img-fluid" src="https://www.plantes-et-sante.fr/images/photo-8.jpg_720_1000_2">
</div>
</div>
</div>
</div>
</div>
Go ahead and resize the screen here, knowing that I need to have the flex display.
https://jsfiddle.net/ero14xqf/
.col-* must always be contained inside .row...
<div class="row">
<div class="col-md-12 d-flex">
<div class="row media block-6 services d-flex align-items-center">
<div class="col-md-6 col-sm-12 d-flex">
<div class="media-body pl-4 pl-md-0 pr-md-4 text-md-left">
<h3 class="heading">Title</h3>
<p class="mb-0">Description</p>
</div>
</div>
<div class="col-md-6 col-sm-12 d-flex">
<div class="d-flex align-items-center justify-content-center">
<img class="img-fluid" src="https://www.plantes-et-sante.fr/images/photo-8.jpg_720_1000_2">
</div>
</div>
</div>
</div>
</div>

Bootstrap 4 - align anchor with heading element in card-head

I am using Bootstrap 4+ to create a card with collapsable card-body, triggered by a link in the card-head.
<div class="card text-left mb-3 mt-3">
<div class="card-head p-3">
<h4>How do we get started?</h4>
<a class="float-right" data-toggle="collapse" href="#collapse1" aria-expanded="false" aria-controls="collapse1">
More
</a>
</div>
<div class="collapse" id="collapse1">
<div class="card card-body">
<p>Content</p>
</div>
</div>
</div>
The tag showing "more" is not lining up vertically inline with the heading element next to it.
It looks like this in chrome:
How can I get the heading and "More" link (vertically) inline with each other? thereby reducing the wasted vertical height.
Just add d-flex justify-content-between classes with your card-head class will resolve your issue. I hope it'll help you out. Thanks
Bootstrap 4 Flexbox - Documentation
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="card text-left mb-3 mt-3">
<div class="card-head p-3 d-flex justify-content-between">
<h4>How do we get started?</h4>
<a class="float-right" data-toggle="collapse" href="#collapse1" aria-expanded="false" aria-controls="collapse1">
More
</a>
</div>
<div class="collapse" id="collapse1">
<div class="card card-body">
<p>Content</p>
</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<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>
You can use d-flex align-items-center which is available in Bootstrap 4+ in your card-head and also you don't need to use float-right instead you can use ml-auto. Something like this
<div class="card text-left mb-3 mt-3">
<div class="d-flex align-items-center card-head p-3">
<h4>How do we get started?</h4>
<a class="ml-auto" data-toggle="collapse" href="#collapse1" aria-expanded="false" aria-controls="collapse1">
More
</a>
</div>
<div class="collapse" id="collapse1">
<div class="card card-body">
<p>Content</p>
</div>
</div>
</div>

bootstrap 4 using float-right got vertical issues

I have comments section on my template, I use w-75 float-right but other column got pull to my comment side.
here my template code.
<div class="col-md-12 mb-3">
....
<!-- comments with no parrent -->
<div class="card mb-3">
<div class="card-body">
....
</div>
</div>
<!-- comments with parrent -->
<div class="card mb-3 w-75 float-right">
....
</div>
<br>
</div>
<!-- comments Form -->
<div class="col-md-12 mb-5">
....
</div>
I wan't like this
Instead of
<div class="card mb-3 w-75 float-right">
Set the left margin to auto, this will push this div element all the way to the right and leave the area to its left clear.
Like this:
<div class='card mb-3 w-75 ml-auto">
You'll want to add .row classes to force a new line, and ensure that each row has exactly 12 columns. To adhere to this, you'll want to remove your w-75 class, and change the parent to col-md-7 in conjunction with offset-md-5 (this totals 12). This allows your card to be offset on desktop screens (with no elements forcing their way in on the left) and stack correctly on mobile screens.
This can be seen in the following (click Run code snippet and then Full page to see the offset):
body {
margin: 0;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<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.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="row">
<div class="col-md-12 mb-3">
....
</div>
</div>
<div class="row">
<div class="col-md-12 mb-3">
<!-- comments with no parent -->
<div class="card mb-3">
<div class="card-body">
....
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-7 offset-md-5">
<!-- comments with parent -->
<div class="card mb-3">
<div class="card-body">
....
</div>
</div>
<br>
</div>
</div>
<div class="row">
<!-- comments Form -->
<div class="col-md-12 mb-5">
....
</div>
</div>

How to align button to right in bootstrap 4

I tried looking this up here but I can't find anything related to this specific problem.
I'm trying to make a header which has a button on the left and right of the screen with a logo in the middle, but whenever I make the window smaller or larger the button on the right doesnt stay aligned.
Small window
Large window
Here is the code:
<header>
<div id="container-fluid">
<div class="row">
<div class=" col-2">
Menu
</div>
<div class="col-8 text-center ">
Logo
</div>
<div class="col-2 float-right">
Contact
</div>
</div>
</div>
</header>
What am I missing here?
Thanks in advance.
Fixed it, code now looks like this:
<body>
<header>
<div id="container-fluid">
<div class="row">
<div class="col">
<span class="float-left">Menu</span>
</div>
<div class="col text-center">
Logo
</div>
<div class="col">
<span class="float-right">Contact</span>
</div>
</div>
</div>
</header>
</body>
wrap your content so it can be aligned according to the parent container.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<header>
<div id="container-fluid">
<div class="row">
<div class="col-2">
<span class="float-left">Menu</span>
</div>
<div class="col-8 text-center">
Logo
</div>
<div class="col-2">
<span class="float-right">Contact</span>
</div>
</div>
</div>
</header>
You can use the flex-bootstrap-class and justify-content for this approach:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="container">
<div class="row d-flex justify-content-between bg-light">
<div class="p-2 bg-dark text-light">
Menu
</div>
<div class="p-2 bg-dark text-light">
Logo
</div>
<div class="p-2 bg-dark text-light">
Contact
</div>
</div>
</div>
You havn't defined what size of column grid you are using. Using col-xs,col-sm, col-md,col-lg will have different effects for the particular code. Run the snippet code in full page below and see how the col-size affects when the browser is resized.
Update - Bootstrap 4 has replaced the col-xs with col- .
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<div id="container-fluid">
Col:xs
<div class="row">
<div class=" col-2">
Menu
</div>
<div class="col-8 text-center ">
Logo
</div>
<div class="col-2 float-right">
Contact
</div>
</div>
</div>
<br>
<br>
<div id="container-fluid">
Col:sm
<div class="row">
<div class=" col-sm-2">
Menu
</div>
<div class="col-sm-8 text-center ">
Logo
</div>
<div class="col-sm-2 float-right">
Contact
</div>
</div>
</div>
<br>
<br>
<div id="container-fluid">
Col:md
<div class="row">
<div class=" col-md-2">
Menu
</div>
<div class="col-md-8 text-center ">
Logo
</div>
<div class="col-md-2 float-right">
Contact
</div>
</div>
</div>
<br>
<br>
<div id="container-fluid">
Col:lg
<div class="row">
<div class=" col-lg-2">
Menu
</div>
<div class="col-lg-8 text-center ">
Logo
</div>
<div class="col-lg-2 float-right">
Contact
</div>
</div>
</div>