CSS Bootstrap put button on right bottom corner - html

I need help putting a button in the bottom-right corner of a Bootstrap col.
I want to put the button where the black outline is in the image below.
<div class="container-fluid m-0">
<div class="d-flex bg-secondary m-0 rounded">
<div class="container">
<div class="row">
<div class="col-sm bg-info">
<div>
</div>
</div>
<div class="col-sm">
<h3> Username</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque dolor leo, iaculis eu rhoncus quis</p>
<p>xxx Followers . xxx Following</p>
</div>
<div class="col-sm bg-danger">
<p class="ml-auto">
<button type="button" class="btn btn-primary">Cancel</button>
</p>
</div>
</div>
</div>
</div>

Check this out--
<div class="container-fluid m-0">
<div class="d-flex bg-secondary m-0 rounded">
<div class="container">
<div class="row">
<div class="col-sm bg-info">
<div>
</div>
</div>
<div class="col-sm">
<h3> Username</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque dolor leo, iaculis eu rhoncus quis</p>
<p>xxx Followers . xxx Following</p>
</div>
<div class="col-sm bg-danger">
<p style="height: 100%" class="d-flex justify-content-end align-items-end">
<button type="button" class="btn btn-primary">Cancel</button>
</p>
</div>
</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
<div class="container-fluid">
<div class="bg-secondary rounded">
<div class="container bg-secondary">
<div class="row align-items-stretch">
<div class="col-12 col-sm bg-info"></div>
<div class="col-12 col-sm">
<div class="py-3">
<h3> Username</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque dolor leo, iaculis eu rhoncus quis</p>
<p>xxx Followers . xxx Following</p>
</div>
</div>
<div class="col-12 col-sm bg-danger">
<div class="h-100 d-flex align-items-end justify-content-end py-3">
<button type="button" class="btn btn-primary">Cancel</button>
</div>
</div>
</div>
</div>
</div>
</div>

There are two methods to implement this...
The first method:
<div class="container-fluid">
<div class="bg-secondary rounded">
<div class="container bg-secondary">
<div class="row align-items-stretch">
<div class="col-12 col-sm bg-info"></div>
<div class="col-12 col-sm">
<div class="py-3">
<h3> Username</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque dolor leo, iaculis eu rhoncus quis</p>
<p>xxx Followers . xxx Following</p>
</div>
</div>
<div class="col-12 col-sm bg-danger">
<div class="h-100 d-flex align-items-end justify-content-end py-3">
<button type="button" class="btn btn-primary">Cancel</button>
</div>
</div>
</div>
</div>
</div>
</div>
This is the easiest one.
The second method:
Go to index.css or App.css or you can go to any other CSS file if you have imported it into your file.
Write this piece of code:
.col-sm {
height: 100%; !important
display: flex; !important
justify-content: flex-end; !important
align-items: flex-end; !important
}
You can also give a class and then write the CSS code based on the class.

Related

Empty div to get spacing according to design using Bootstrap

For bannerimage section which has texts on the specific position, I don't want to write custom CSS to place the div. The below code fits correctly according to design and it's good in responsive also. I've not used this code everywhere but only in 1 section where there is a condition to display div or text at a specific position. I don't want to write custom CSS. But using bootstrap empty div problem is solving, Is this correct or not.
<div class="mainbannerimagewithtext">
<div class=" row-cols-1 row-cols-md-3 g-4 py-5 ">
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
</div>
</div>
<div class=" row-cols-1 row-cols-md-3 g-4 py-5 ">
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
</div>
</div>
<div class=" row-cols-1 row-cols-md-3 g-4 py-5 ">
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
</div>
</div>
<div class=" row-cols-1 row-cols-md-3 g-4 py-5 ">
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
</div>
</div>
<div class=" row-cols-1 row-cols-md-3 g-4 py-5 media ">
<div class="col px-5 ">
<p class="twentyfive ">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
<p class="fifteen">Lorem ipsum dolor sit amet, consectetur adipiscing elitLorem ipsum dolor sit amet,
consectetur adipiscing elitLorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</div>
<div class="col">
</div>
<div class="col">
</div>
</div>
<div class="container py-5">
<div class=" ">
<div class="text-start px-5 py-5">
<p class="adm-nf-twenty"></p>
<p class="adm-nf-twentyitalic"></p>
</div>
</div>
</div>
<div class="container py-5">
<div class=" ">
<div class="text-start px-5 py-5">
</div>
</div>
</div>
<div class="container py-5">
<div class=" ">
<div class="text-start px-5 py-5">
</div>
</div>
</div>
<div class="container py-5">
<div class=" ">
<div class="text-start px-5 py-5">
</div>
</div>
</div>
<div class="container py-5">
<div class="bluebox ">
<div class="text-start px-5 py-5">
<p class="twenty">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
<p class="twentyitalic">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
<p class="fifteenwhite">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
<p class="fifteenwhite">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
<p class="fifteenwhite"> Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
</div>
</div>
</div>
My opinion is you should consider using offset for the best practice, also you can customize it for all available screen size Bootstrap provided.
Like this for example :
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-md-4">normal .col-md-4</div>
<div class="col-md-4 offset-md-4">.col-4 getting offset for 4 col in md screen size</div>
</div>
<div class="row">
<div class="col-md-3 offset-md-3">.col-md-3 getting offset for 3 col in md screen size</div>
<div class="col-md-3 offset-md-3">.col-md-3 getting offset for 3 col in md screen size</div>
</div>
<div class="row">
<div class="col-md-6 offset-md-3">.col-md-6 getting offset for 3 col in md screen size</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
Also always remember offset always arrange the column to the right

bootstrap cards aren't adjusting height when one card gets more content

I have 4 cards.
In a scenario from the backend for one card, there will be more text in one particular card. but the expected output is: If one card gets big content than other cards. all cards have to be at the same height and cards which don't have much content will be vertically aligned. (But that card's height should be the same as the big content card).
I used bootstrap cards and d-flex. but I couldn't achieve it.
Code Snippet
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<h1 class="text-center mb-5">Our other packages</h1>
<div class="slick-swipe v-align-center-slick-contents">
<div class="mr-3 p-2">
<div class="card text-center level-4 bg-1">
<div class="border-top-thick"></div>
<div class="card-body">
<h6>Bigger Content Big Big</h6>
</div>
</div>
</div>
<div class="mr-3 p-2">
<div class="card text-center level-4 bg-2">
<div class="border-top-thick"></div>
<div class="card-body">
<h6>Gold</h6>
</div>
</div>
</div>
<div class="mr-3 p-2">
<div class="card text-center level-4 bg-3">
<div class="border-top-thick"></div>
<div class="card-body">
<h6>Thee</h6>
</div>
</div>
</div>
<div class="mr-3 p-2">
<div class="card text-center level-4 bg-4">
<div class="border-top-thick"></div>
<div class="card-body">
<h6>Diamond</h6>
</div>
</div>
</div>
<div class="mr-3 p-2">
<div class="card text-center level-4 bg-5">
<div class="border-top-thick"></div>
<div class="card-body">
<h6>More Packages</h6>
</div>
</div>
</div>
</div>
</div>
You will have to add a class in your css files to specify the height for the cards.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<h1 class="text-center mb-5">Our other packages</h1>
<div class="slick-swipe v-align-center-slick-contents">
<div class="mr-3 p-2">
<div class="card cards text-center level-4 bg-1">
<div class="border-top-thick"></div>
<div class="card-body">
<h6>Bigger Content Big Big</h6>
</div>
</div>
</div>
<div class="mr-3 p-2">
<div class="card cards text-center level-4 bg-2">
<div class="border-top-thick"></div>
<div class="card-body">
<h6>Gold</h6>
</div>
</div>
</div>
<div class="mr-3 p-2">
<div class="card cards text-center level-4 bg-3">
<div class="border-top-thick"></div>
<div class="card-body">
<h6>Thee</h6>
</div>
</div>
</div>
<div class="mr-3 p-2">
<div class="card cards text-center level-4 bg-4">
<div class="border-top-thick"></div>
<div class="card-body">
<h6>Diamond</h6>
</div>
</div>
</div>
<div class="mr-3 p-2">
<div class="card cards text-center level-4 bg-5">
<div class="border-top-thick"></div>
<div class="card-body">
<h6 style="font-size: 1.5rem;"> Vestibulum feugiat congue nulla vitae semper. Mauris id nibh nisi. Aliquam vel semper velit, sit amet hendrerit ipsum. Vestibulum sodales dictum ex vitae accumsan. Vestibulum varius ut mauris at iaculis. Suspendisse sodales pulvinar diam, non lobortis risus. Etiam sagittis convallis leo, a scelerisque eros laoreet et. </h6>
</div>
</div>
</div>
<div class="mr-3 p-2">
<div class="card cards text-center level-4 bg-5">
<div class="border-top-thick"></div>
<div class="card-body">
<h6>More Packages</h6>
</div>
</div>
</div>
</div>
</div>
.cards {
height: 200px;
}
Here is an example

Combine elements into a carousel in mobile view?

Here are the elements that I want them to be combined into a swipeable carousel. Is there a way to do this? I just want them to turn into carousel only in mobile view.
Here is the HTML if needed. Thanks for help.
<div class="col-md-5 col-xs-12 d-flex justify-content-center little">
<div class="col launch">
<div class="row-sm-3 row-md-4 fx">
<div class="row d-flex justify-content-center resim"><img src="css/img/Icon1.png" alt=""></div>
<div class="row d-flex justify-content-center baslik">First 7 Days Free</div>
<div class="row d-flex justify-content-center yazi">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut.</div>
</div>
<div class="row-sm-3 row-md-4 fx">
<div class="row d-flex justify-content-center resim"><img src="css/img/Icon2.png" alt=""></div>
<div class="row d-flex justify-content-center baslik">Fully Support</div>
<div class="row d-flex justify-content-center yazi">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut.</div>
</div>
</div>
<div class="col star">
<div class="row-sm-3 row-md-4 fx">
<div class="row d-flex justify-content-center resim"><img src="css/img/Icon3.png" alt=""></div>
<div class="row d-flex justify-content-center baslik">Modern Flat Design</div>
<div class="row d-flex justify-content-center yazi">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut.</div>
</div>
<div class="row-sm-3 row-md-4 fx" >
<div class="row d-flex justify-content-center resim" ><img src="css/img/Icon4.png" alt="" id="ozel"></div>
<div class="row d-flex justify-content-center baslik">User Friendly</div>
<div class="row d-flex justify-content-center yazi">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut.</div>
</div>
</div>
</div>
I guess the only opportunity is to have both code for your grid-like display (as shown above) and for your carousel like this:
<!-- Code of your grid view -->
<div id="gridView">
<div class="col-md-5 col-xs-12 d-flex justify-content-center little">
...
</div>
</div>
<!-- Code of your carousel -->
<div id="carouselExampleControls" class="carousel slide mx-3 my-2" data-ride="carousel">
...
</div>
Next use Bootstrap display property to properly show and hide the containers, e.g., d-md-none to hide on md and wider screens and d-none d-md-block to hide on screens smaller than md:
<!-- Code of your grid view -->
<div id="gridView" class="d-none d-md-block">
<div class="col-md-5 col-xs-12 d-flex justify-content-center little">
...
</div>
</div>
<!-- Code of your carousel -->
<div id="carouselExampleControls" class="carousel slide mx-3 my-2 d-md-none" data-ride="carousel">
...
</div>
Since you are using d-flex, I put the extra <div id="gridView"> around it.
Here is an example of a Bootstrap carousel with captions:
<div id="carouselExampleCaptions" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleCaptions" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleCaptions" data-slide-to="1"></li>
<li data-target="#carouselExampleCaptions" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="..." class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>First slide label</h5>
<p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
</div>
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Second slide label</h5>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Third slide label</h5>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleCaptions" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleCaptions" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
You can easily integrate your containers there and combine it with the above mentioned approach.
Good luck!

HTML & CSS: Bootstrap columns

I'm trying to create a grid system but I can't figure how to put the columns. To be more clear, I want the horizontal cards to be one under another without being divided. I tried changing the orded of the blocks but didn't seem to work at all. I'm using Bootstrap 4.
<div class="row">
<div class="col-lg-8 col-md-12">
<div class="card">
<div class="card-header card-header-text card-header-warning">
<div class="card-text">
Welcome back, <b><?php echo $display_name; ?></b>!
</div>
</div>
<div class="card-body">
<h4 class="card-title">Info</h4>
<p class="card-text">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras odio dui, sodales vitae fringilla quis, porta in nunc..
</p>
<footer class="blockquote-footer">Lorem</footer>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header card-header-text card-header-danger">
<div class="card-text">
<h4 class="card-title">News</h4>
</div>
</div>
<?php
while($row = $stmtNews->fetch(PDO::FETCH_ASSOC)){
$row['date'] = date('j M', strtotime($row['date']));
?>
<div class="card-body" style="max-height: 80px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
<?php echo $row['news']; ?>
<div class="card-footer">
<div class="card-text">
<small class="text-time"><?php echo $row['date']; ?></em></small>
</div>
</div>
</div>
<div class="dropdown-divider" style="margin: 15px;"></div>
<?php
}
?>
</div>
</div>
<div class="col-lg-8 col-md-12">
<div class="card">
<div class="card-header card-header-text card-header-warning">
<div class="card-text">
Welcome back, <b><?php echo $display_name; ?></b>!
</div>
</div>
<div class="card-body">
<h4 class="card-title">Info</h4>
<p class="card-text">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras odio dui, sodales vitae fringilla quis, porta in nunc...
</p>
<footer class="blockquote-footer">Lorem</footer>
</div>
</div>
</div>
</div>
I don't know exactly what you want to achieve, but maybe this approach could help you:
<div class="row">
<div class="col-sm-9">
Level 1: .col-sm-9
<div class="row">
<div class="col-sm-12">
Level 2: .col-12
</div>
<div class="col-sm-12">
Level 2: .col-12
</div>
</div>
</div>
<div class="col-sm-2">
Level 1: .col-sm-2
<div class="row">
<div class="col-sm-12">
Level 2: .col-12 with defined or dynamic height
</div>
</div>
</div>
</div>
It results in this grid:
It may not be the best idea, but it may be a first approach to solve your problem.

Responsive custom div table

I had to make div table, because I didn't see a way to do it with a bootstrap table element.
Here is image:
Here is the code:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row border-top bg-primary pt-3 pb-0 mt-5">
<div class="col-12">
<p class="text-white"><b>Lorem ipsum</b></p>
</div>
</div>
<div class="row border-left border-right text-center">
<div class="col-8 pt-3 pb-0 border-right">
<p>Lorem ipsum</p>
</div>
<div class="col-4 pt-3 pb-0">
<p>Lorem ipsum</p>
</div>
</div>
<div class="row border text-center">
<div class="col-10">
<div class="row">
<div class="col pt-3 pb-0 border-right">
<p>Lorem ipsum dolor sit amet, consectetur</p>
</div>
<div class="col pt-3 pb-0 border-right">
<p>Lorem ipsum dolor sit amet, consectetur</p>
</div>
<div class="col pt-3 pb-0 border-right">
<p>Lorem ipsum dolor sit amet, consectetur</p>
</div>
<div class="col pt-3 pb-0 border-right">
<p>Lorem ipsum dolor sit amet, consectetur</p>
</div>
<div class="col pt-3 pb-0 border-right">
<p>Lorem ipsum dolor sit amet, consectetur</p>
</div>
</div>
<div class="row border-top">
<div class="col bg-primary-dark pt-3 pb-0" style="width: 80%; flex-basis: unset;">
<p class="text-white"><b>Lorem ipsum</b></p>
<p class="text-white">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
</p>
</div>
<div class="col border-right" style="width: 20%; flex-basis: unset;"></div>
</div>
<div class="row border-top">
<div class="col border-right" style="width: 20%; flex-basis: unset;"></div>
<div class="col bg-info-dark pt-3 pb-0 border-right" style="width: 80%; flex-basis: unset;">
<p class="text-white"><b>Lorem ipsum</b></p>
<p class="text-white">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
</p>
</div>
</div>
</div>
<div class="col-2 pt-3">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore
</p>
</div>
</div>
Now I want this to be responsive. Horizontal scroll, or any other way, any suggestions would be greatly appreciated
The class col in bootstrap will divide the row into amount of col elements you added.To make it responsive specify width of element for each screen type, using such classes as col-sm-12 (full width on small devices), col-md-6 (two column grid for medium screens) etc. Don't forget, bootstrap is mobile first.