Removing space created inside my container [duplicate] - html

This question already has answers here:
How to overlay images
(11 answers)
Closed 3 years ago.
I have a container that has an image and on top of that image a button, but inside the container some "extra" space was created, at the right. I need to remove this extra space because its taking too much space. 3 horizontal images are aligned at the center, all while using a flex display. Using bootstrap.
There are no sizes in width or height, it is only the image behind this button.
<br>
<h1 class="text-center">¿Qué temas te interesan?</h1>
<div class="row justify-content-around">
<div class="d-flex align-content-center flex-wrap container-img-intereses">
<br> <img src="/btn-desarrollo-ing.png" width="350px"/>
<button type="button" class="btn btn-primary" id="wrapper-button">Carreras</button>
</div>
<div class="d-flex align-content-center flex-wrap">
<a href="#"> <br>
<img src="/btn-diseno-ux.png" width="350px"/></a>
</div>
<div class="d-flex align-content-center flex-wrap">
<a href="#"><br>
<img src="/btn-mkt.png" width="350px"/></a>
</div>
</div>
<div class="row justify-content-around">
<div class="d-flex align-content-center flex-wrap">
<a href="#"> <br>
<img src="/btn-negocios.png" width="350px"/></a>
</div>
<div class="d-flex align-content-center flex-wrap">
<a href="#"> <br>
<img src="/btn-comunidad.png"width="350px"/></a>
</div>
<div class="d-flex align-content-center flex-wrap">
<a href="#"> <br>
<img src="/btn-produccion-aud.png"width="350px"/></a>
</div>
</div>
<br>
<div class="d-flex justify-content-center flex-wrap">
<img src="/btn-crecimiento-prof.png"width="350px"/>
</div>
.container-img-intereses {
border: 1px solid black;
display: inline-flex;
align-items: center;
text-align: center;
}
.container-img-intereses > img {
position: absolute;
z-index: -1;
}
.btn {
right: 80px;
top: 40px;
position: relative;
z-index: 1;
}
https://imgur.com/a/JEo68bF i have to repeat this and make it into a process so a button is always on top of these rectangles.

Actually if you need to show the button up the image you are using position relative to button. So button will be take it's width.
Position relative: If you set to position relative, elements take up the same amount of space at the same exact position it was supposed to take as if its position was static.It can however, appear to be pushed to a different location visually. So that's why it's taking sapce around the image.
Position absolute: Position absolute takes the document out of the document flow. This means that it no longer takes up any space like what static and relative does.
So You need to add position absolute on button and position relative to it's container container-img-intereses

Not sure this works for you since it isn't clear what you want to do with that button. You could give the parent div a position of relative and make the button absolutely positioned with the div, and then adjust your HTML and CSS accordingly, see Snippet:
.container-img-intereses {
display: inline-flex;
align-items: center;
text-align: center;
position: relative;
}
.container-img-intereses>img {
position: absolute;
z-index: -1;
}
.btn {
position: absolute;
left: 50%;
bottom: 0px;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha256-YLGeXaapI0/5IgZopewRJcFXomhRMlYYjugPLSyNjTY=" crossorigin="anonymous" />
<h1 class="text-center">¿Qué temas te interesan?</h1>
<div class="row justify-content-around">
<div class="d-flex align-content-center flex-wrap container-img-intereses">
<img src="/btn-desarrollo-ing.png" width="350px" />
<button type="button" class="btn btn-primary" id="wrapper-button">Carreras</button>
</div>
<div class="d-flex align-content-center flex-wrap">
<img src="/btn-diseno-ux.png" width="350px" />
</div>
<div class="d-flex align-content-center flex-wrap">
<img src="/btn-mkt.png" width="350px" />
</div>
</div>
<div class="row justify-content-around">
<div class="d-flex align-content-center flex-wrap">
<img src="/btn-negocios.png" width="350px" />
</div>
<div class="d-flex align-content-center flex-wrap">
<img src="/btn-comunidad.png" width="350px" />
</div>
<div class="d-flex align-content-center flex-wrap">
<img src="/btn-produccion-aud.png" width="350px" />
</div>
</div>
<br>
<div class="d-flex justify-content-center flex-wrap">
<img src="/btn-crecimiento-prof.png" width="350px" />
</div>

Related

creating three dots vertically with span and align them

I'm trying to create three vertical dots and align the bottom left of my container with css and bootstrap 5. exactly like the pic below:
my HTML and CSS:
.dot {
border-radius: 50%;
height: 12px;
width: 12px;
background: linear-gradient(90deg, #76b3fe, #8680e4);
}
.selected-dot {
height: 20px;
width: 20px;
background: #97cdfe;
}
<section class="slider-bg-1 d-flex align-items-end">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-5 d-flex flex-column justify-content-center pt-4 pt-lg-0 order-2 order-lg-1">
<h1 class="head-font-size">Choose a powerful design for your Start-up</h1>
<h6 claas="caption-text-color">Get your freebie template now</h6>
<div class="d-lg-flex">
<div class="mt-5"><button class="my-btn" type="submit">Discover</button></div>
</div>
</div>
<div class="col-lg-5 col-md-12 col-sm-12 order-1 order-lg-2 d-flex justify-content-center">
<img src="Assets/home-slider/slider-m-1.png" class="img-fluid img-slider" alt="">
</div>
</div>
</div>
<span class="dot selected-dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</section>
this is my output
how can i align the vertically and move them to bottom left of container? because when i use div for wrapping they disappear
1st: wrap the dots in a container. I used a section with the class: .dot-wrapper.
2nd: give the wrapper a width: min-content;. With that, it will only be as wide as the seclected dot.
3rd: to cenetr the dots, give them a margin left and right of auto;
.dot {
border-radius: 50%;
height: 12px;
width: 12px;
background: linear-gradient(90deg, #76b3fe, #8680e4);
margin: 5px auto;
}
.selected-dot {
height: 20px;
width: 20px;
background: #97cdfe;
}
.dot-wrapper {
width: min-content;
}
<section class="slider-bg-1 d-flex align-items-end">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-5 d-flex flex-column justify-content-center pt-4 pt-lg-0 order-2 order-lg-1">
<h1 class="head-font-size">Choose a powerful design for your Start-up</h1>
<h6 claas="caption-text-color">Get your freebie template now</h6>
<div class="d-lg-flex">
<div class="mt-5"><button class="my-btn" type="submit">Discover</button></div>
</div>
</div>
<div class="col-lg-5 col-md-12 col-sm-12 order-1 order-lg-2 d-flex justify-content-center">
<img src="Assets/home-slider/slider-m-1.png" class="img-fluid img-slider" alt="">
</div>
</div>
</div>
<section class="dot-wrapper">
<div class="dot selected-dot"></div>
<div class="dot"></div>
<div class="dot"></div>
</section>
</section>
it's quite easy, you can wrap the dots with a div container like this
<!--Column Dots -->
<div class="dot-container">
<span class="dot selected-dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>
and style the container as below
.dot-container{
width: 15px;
display: flex;
flex-direction:column;
align-items:center;
}
and for better styling. give dot class some amrgin like margin: 3px 0;
here is a codpen : https://codepen.io/shammlo/pen/QWKggNX?editors=1100

Boostrap grid height and placing row with height: auto

I am doing a simple page with a bootstrap grid and I am having some problems with placing the middle row occupying the full height in the middle.
These are the 3 rows: page
I want to place the row with the logo in the middle, but I am having problems with it. I placed height: 100%;, height: auto;. I even placed the container height to 100% and auto and nothing works!
I think there is a concept about bootstrap heigh that I am missing, because its the heigh that I have problems
html:
<div class="container-fluid">
<div class="row">
<div class="col-md-1 col-2">
<img id="menuIcon" (click)="toggleRightSidenav()" onmouseover="this.src='../../../assets/Images/generic/menuIcon_hover.png'" src="/assets/Images/generic/menuIcon.png" onmouseout="this.src='/assets/Images/generic/menuIcon.png'">
</div>
<div class="col-md-10 col-8">
</div>
<div class="col-md-1 col-2">
<img id="helpIcon" routerLink="/guide" onmouseover="this.src='../../../assets/Images/home/helpIconHover.png'" src="/assets/Images/home/helpIcon.png" onmouseout="this.src='/assets/Images/home/helpIcon.png'">
</div>
</div>
<div class="row row align-items-center mh-100" >
<div class= "col-md-12">
<img id="logo" src="/assets/Images/home/Logo.png">
</div>
</div>
<div class="row align-items-center justify-content-around fixed-bottom">
<div class="col-md-2 col-sm-2">
<img id="addButton" routerLink="/addPlayer" onmouseover="this.src='../../../assets/Images/generic/addIcon_hover.png'" src="../../../assets/Images/generic/addIcon.png" onmouseout="this.src='/assets/Images/generic/addIcon.png'" />
</div>
<div class="col-md-2 col-sm-2">
<p>Players Waiting: {{playerWaiting}} </p>
</div>
<div class="col-md-2 col-sm-2">
<p>Listed Players: {{playersListed}}</p>
</div>
<div class="col-md-2 col-sm-2">
<img id="searchButton" routerLink="/search" onmouseover="this.src='../../../assets/Images/generic/searchIcon_hover.png'" src="../../../assets/Images/generic/searchIcon.png" onmouseout="this.src='/assets/Images/generic/searchIcon.png'" />
</div>
</div>
</div>
css:
div{
border: yellow 1px solid;
}
#menuIcon{
width: 100%;
height: auto;
}
#helpIcon{
width: 100%;
height: auto;
}
#addButton{
width: 100%;
height: auto;
max-width: 127px;
}
#searchButton{
width: 100%;
height: auto;
max-width: 127px;
}
https://www.codeply.com/p/Xd0xi5hFNc
Couple of things.
To be able to fill several rows, you'd need a height for the container div.
Current HTML
<div class="container-fluid">
Update as
<div class="container-fluid d-flex vh-100 flex-column">
Now you can easily make your middle div fill the remaining gap by adding a fill-height class.
Current HTML
<div class="row row align-items-center mh-100" >
Update as
<div class="row row align-items-center fill-height">
Add this to your css
.fill-height {
flex: 1;
}
.fixed-bottom {
position: sticky;
}
jsFiddle

center align (V & H) a div with an img in a parent div?

I would like to align both an image and a div (horizontally and vertically centerd) inside parent div, but I can not, I have been trying to do it for 2 days. I am using bootstrap 4, HTML5, CSS3
Images somehow do not show in the code snippet
<!-- Welcome Area -->
<div class="container-fluid p-0">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12" style="background-image: url(assets/images/main-img.jpg);">
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12 text-center">
<img src="assets/images/auscene-icon-buttons-12-t.png" class="img-responsive img-fluid" id="welcome-area-img" style="visibility: hidden;" />
</div>
</div>
</div>
</div>
<!-- End Welcome Area -->
<!-- Main area -->
<div class="container-fluid">
<div class="row pt-4 pb-4 mb-5 px-0">
<div class="col-sm-2 col-md-1 col-lg-1 col-xl-1 px-0 text-center" style="width: 10% !important;" id="show-last-news-title">
<img src="assets/images/auscene_icon_button_01_Y9u_icon.ico" class="img-responsive img-fluid pt-4" id="auscene-image-1">
</div>
<div class="col-sm-2 col-md-1 col-lg-1 col-xl-1 px-0 text-center" style="width: 10% !important;" id="show-last-how-to-title">
<img src="assets/images/auscene_icon_button_02_xYm_icon.ico" class="img-responsive img-fluid pt-4" id="auscene-image-2">
</div>
<div class="col-sm-4 col-md-8 col-md-push-8 col-lg-8 col-xl-8 px-0" style="width: 60% !important;">
<h1 class="text-left" style="font-size:3.5rem; color:#5acfc2; font-family:LouisGeorgeCafe;" id="welcome-area-title">Issue #01
</h1>
<h1 class="text-left" style="font-size:2rem; font-family:LouisGeorgeCafe;" id="welcome-area-subtitle"></h1>
</div>
<div class="col-sm-2 col-md-1 col-lg-1 col-xl-1 px-0 text-center" style="width: 10% !important;" id="show-last-guide-to-aucians-title">
<img src="assets/images/auscene_icon_button_03_ClJ_icon.ico" class="img-responsive img-fluid pt-4" id="auscene-image-3">
</div>
<div class="col-sm-2 col-md-1 col-lg-1 col-xl-1 px-0 text-center" style="width: 10% !important;" id="show-last-in-depth-title">
<img src="assets/images/auscene_icon_button_04_JP2_icon.ico" class="img-responsive img-fluid pt-4" id="auscene-image-4">
</div>
</div>
</div>
<!-- End of Main area -->
Updated After solving the problem of not being able to align an image dead center overlaps the another, now the div takes automatically height of 20px instead of div background image's height
Below you find the desired effect by use of latest Bootstrap and additional styling. Please note that this also rectifies the inconsistencies you have in your code example with the proper headers, image links and bootstrap classes.
I have placed styling inline but you can move these to a separate file if you want.
The container is set to 100% of the view height in order to center the large image (the containing row) vertically.
The smaller image is vertically aligned by the calc function where we place the image 50% minus half the image height absolutely from the top (you'll have to take this into consideration if you add the #media ref below).
Please note that both images are responsive but since the smaller image maintains its original size for longer before resizing it looks like it's bigger than the background image on smaller devices.
You can alter this with the #media rule or with more advanced CSS but that's outside of the scope of your question.
(Consider using a background image instead as Ng-Sek-Long suggests)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Centered images</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
<body>
<!-- Welcome area -->
<div class="container-fluid d-flex justify-content-center align-items-center" style="min-height: 100vh;">
<div class="row">
<div class="col-xs-12" style="position: relative;">
<img src="https://www.gruberreisen.at/fileadmin/redakteure/Website/slider/Header_Startseite1.jpg" class="img-fluid" />
<div style="position: absolute; left: 0; top: calc(50% - 132px); width: 100%; text-align: center;">
<img src="http://placehold.it/269x265/ccc.jpg" class="img-fluid" />
</div>
</div>
</div>
</div>
</body>
</html>
See the code snippet below for an example:
.container {
position: relative;
display: inline-block;
vertical-align: middle;
width: 350px;
height: 250px;
}
.img-responsive {
box-sizing: border-box;
width: 350px;
height: 250px;
border-radius: #field-border-radius;
}
.overlay {
position: absolute;
top: 25%;
left: 25%;
}
.icon {
width: 175px;
height: 125px;
object-fit: fill;
}
<!-- Welcome Area -->
<div class="container-fluid p-0">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 container">
<img src="https://www.gstatic.com/webp/gallery/4.sm.jpg" class="img-responsive img-fluid" />
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 text-center overlay">
<img src="https://via.placeholder.com/175x125" class="img-responsive img-fluid icon" />
</div>
</div>
</div>
</div>
<!-- End Welcome Area -->
If you are looking for to align the both div and img to center you can add text-center to the parent element as well as to align left add text-left and for right text-right. But since you are having bootstrap col in your div it will have the padding when you set right or left. You need to write padding-left:0 or padding-right:0 according to the alignment.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<!-- Welcome Area -->
<div class="container-fluid p-0">
<div class="row">
<div class=" col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 text-center">
<img src="https://source.unsplash.com/300x300" class="img-responsive img-fluid" />
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 ">
<img src="https://source.unsplash.com/300x300?x" class="img-responsive img-fluid" style="z-index: auto;" />
</div>
</div>
</div>
</div>
If you are looking for them to keep in both side next to one , you need to change your HTML DOM like this.
col-**-12 which means takes the width:100%. If you want your child next to one your to give each child a 50% of the width. So you need to change it it col-**-6 which gives the 50% of width.According to the logic now your parent is row and it has 2 div elements which are childs and having col-**-6 for both. And inside they have the img. If you feel the padding is unnecessary to you, so you can add padding: 0 !important; margin: 0 !important; to the element who have the class col-**
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<!-- Welcome Area -->
<div class="container-fluid p-0">
<div class="row">
<div class=" col-xs-6 col-sm-6 col-md-6 col-lg-6 col-xl-6 parent">
<img src="https://source.unsplash.com/300x300" class="img-responsive img-fluid" />
</div>
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6 col-xl-6 ">
<img src="https://source.unsplash.com/300x300?x" class="img-responsive img-fluid" style="z-index: auto;" />
</div>
</div>
</div>
In order to keep your img inside the larger one you need to set the element to position:absolute which make your element to non identifiable by html. Now you can position it as you wanted.
.parent {
position: relative;
}
.parent>img {
height: 530px;
width: 1820px;
object-fit: cover;
}
.inner-child {
position: absolute !important;
top: 50%;
-webkit-transform: translateY(-50%);
-moz-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
text-align: center;
}
.inner-child>img {
height: 269px;
width: 259px;
box-shadow: 0 0 5px 3px black;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<!-- Welcome Area -->
<div class="container-fluid p-0">
<div class="row">
<div class=" col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 parent">
<img src="https://source.unsplash.com/300x300" class="img-responsive img-fluid" />
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 inner-child">
<img src="https://source.unsplash.com/300x300?x" class="img-responsive img-fluid" style="z-index: auto;" />
</div>
</div>
</div>
</div>
From your comment:
Image 1 in parent div will be 1820px X 530px (or more in width) image 2 - inside inner div- is 269px X 259px,
Seems like this is what you want, a simple css will be much better than trying to use bootstrap to do the job.
.outter-div {
width: 1820px;
height: 530px;
background-image: url("https://source.unsplash.com/collection/190727/1820x530");
}
.inner-img {
position: relative;
transform: translate(-50%, -50%);
top: 50%;
left: 50%;
}
<div class="outter-div">
<img class="inner-img" src="https://source.unsplash.com/collection/190727/269x259">
</div>
You only need to use:
.v-center {
top:50%;
left:0;
right:0;
transform: translateY(-50%);
}
The rest of the positioning can be done with Bootstrap classes.
<div class="container-fluid">
<div class="row no-gutters mvh-100 align-items-center">
<div class="col-12">
<img src="http://placehold.it/1860x530" class="img-fluid">
<div class="text-center position-absolute v-center">
<img src="http://placehold.it/269x265/444" class="img-fluid" style="z-index: auto;">
</div>
</div>
</div>
</div>
Demo: https://www.codeply.com/go/umBZgxLzEN
Note: Make sure you follow the Bootstrap docs. The -xs infix no longer exist, and there shouldn't be col directly in other col.

Issue aligning div's using width and float

So what I am trying to do is align these divs within a bootstrap card. My issue is, I am able to get the left half of it right, but I can't figure out how to align the far right elements. I am currently using width percentages to allow this to stay responsive, though I have one thing set as fixed due to pictures always being the same size.
<div class="card" style="width:65%;float:left;">
<h5 class="card-header">Window Latch Black (Small)</h5>
<div class="card-body clearfix text-center" style="width:100%;display:inline-block;background-color: aqua;">
<div class="cartimage" style="background-color:red;float:left">
<img class="rounded-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140">
</div>
<div class="carttext" style="height:50%;width:75%;background-color:green;">
khjg
</div>
<div class="cartamt" style="height:50%;width:75%;background-color:yellow;">
amt
</div>
<div class="cartprice" style="height:50%;width:15%;background-color:purple;float:right">
price
</div>
<div class="cartbutton" style="height:50%;width:15%;background-color:pink;float:right">
button
</div>
</div>
</div>
You need to adjust the order and replace 15% with 25% to have a total of 100% per row. You need to also set a height to parent container to use % height with child element:
.rounded-circle {
border-radius:50%;
vertical-align:top;
}
<div class="card" style="width:65%;float:left;">
<h5 class="card-header">Window Latch Black (Small)</h5>
<div class="card-body clearfix text-center" style="width:100%;display:inline-block;background-color: aqua;height:140px">
<div class="cartimage" style="background-color:red;float:left">
<img class="rounded-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140">
</div>
<div class="cartprice" style="height:50%;width:25%;background-color:purple;float:right">
price
</div>
<div class="carttext" style="height:50%;width:75%;background-color:green;">
khjg
</div>
<div class="cartbutton" style="height:50%;width:25%;background-color:pink;float:right">
button
</div>
<div class="cartamt" style="height:50%;width:75%;background-color:yellow;">
amt
</div>
</div>
</div>
By the way, since you are using Bootstrap V4 you can rely on flex to create your layout:
.rounded-circle {
border-radius: 50%;
vertical-align: top;
}
.cartprice {
background: red;
flex-basis: 75%;
}
.carttext {
background: green;
flex-basis: 25%;
}
.cartbutton {
background: blue;
flex-basis: 75%;
}
.cartamt {
background: yellow;
flex-basis: 25%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="card">
<h5 class="card-header">Window Latch Black (Small)</h5>
<div class="card-body text-center d-flex">
<div class="cartimage">
<img class="rounded-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140">
</div>
<div class="d-flex flex-wrap w-100" >
<div class="cartprice">
price
</div>
<div class="carttext">
khjg
</div>
<div class="cartbutton">
button
</div>
<div class="cartamt">
amt
</div>
</div>
</div>
</div>
If you are using bootstrap4, I don't understand why using float...Use boostartp4 [Flex Utilities] classes instead to make these type of grid layout...Also for good practice try to wrap your divs into a wrapper divs
Stack Snippet
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="card">
<h5 class="card-header">Window Latch Black (Small)</h5>
<div class="card-body text-center p-0 d-flex no-gutters" style="background-color: aqua;">
<div class="cartimage" style="background-color:red;">
<img class="rounded-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140">
</div>
<div class="d-flex flex-column" style="flex: 2;">
<div class="carttext col" style="background-color:green;">
khjg
</div>
<div class="cartamt col" style="background-color:yellow;">
amt
</div>
</div>
<div class="d-flex flex-column col">
<div class="cartprice col" style="background-color:purple">
price
</div>
<div class="cartbutton col" style="background-color:pink">
button
</div>
</div>
</div>
</div>

How to align div to bottom inside div with Bootstrap?

html, body, .sidebar-container, .sidebar-row {
height: 100%;
}
.sidebar {
background-color: #2C3544;
}
#media (min-width: 992px) {
.sidebar {
position: fixed;
top: 0;
left: 0;
bottom: 0;
z-index: 1000;
display: block;
background-color: #2C3544;
}
}
img{
margin: auto;
display: block;
}
.sidebar-image{
margin-top: 15px;
}
.sidebar-items{
margin-top: 15px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid sidebar-container">
<div class="row sidebar-row">
<div class="col-md-2 sidebar">
<div class="container-fluid">
<div class="col-md-12 sidebar-image">
<img src="assets/logo-white.png" width="75px" height="75px"/>
</div>
</div>
<div class="row sidebar-items">
<div class="col-md-12">
<ul class="list-group">
<li class="list-group-item">Dashboard</li>
<li class="list-group-item">Projects</li>
<li class="list-group-item">Statistics</li>
</ul>
</div>
</div>
<div class="row align-bottom">
hafldjalfjsdlfsjdlfsjlfs
</div>
</div>
<div class="col-md-10 offset-md-2 content">
Main Content
</div>
</div>
</div>
I wrote this HTML/CSS code trying to align a div to the bottom inside another div:
I want to align this last div in the col-md-2 to the bottom of the sidebar-container which height is 100%. I tried adding the bootstrap class align-bottom but somehow this doesn't work. Could anyone help me out?
Suppose you have 2 divs. Div A(Outer) and Div B(Inner). To achieve your task just place Div B code in Div A code and in Div B css class add this
position : absolute
bottom : 0
You can also just use bootstrap flexbox to do this.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<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>
<div class="d-flex align-items-start flex-column bg-success" style="height: 200px;">
<div class="mb-auto p-2">Flex item-1</div>
<div class="p-2">Flex item-2</div>
<div class="p-2">Flex item-3</div>
</div>
<div class="d-flex align-items-end flex-column bg-info" style="height: 200px;">
<div class="p-2">Flex item-a</div>
<div class="p-2">Flex item-b</div>
<div class="mt-auto p-2">Flex item-c</div>
</div>
align items to the left or right make sure that you include the entire d-flex align-items-end flex-column on the parent element and choose start or end depending if you want it to be aligned left or right.
align item to the bottom Then, use mt-auto on the div that you want to stick to the bottom of the parent.
When using Bootstrap grid system, my go-to solution is like this:
add d-flex to each col-*
add d-flex flex-column to each card-body
add mt-auto mx-auto to the last element (or last div of elements) I want to stick to the end
This prevents any further styling mess-up in my opinion.
Relevant Documentation:
Flex Alignment in Bootstrap 5.0: https://getbootstrap.com/docs/5.0/utilities/flex/#align-items
Vertical Alignment in Bootstrap 5.0: https://getbootstrap.com/docs/5.0/utilities/vertical-align/
Relevant Code:
What worked for me to align a div (of text) at the bottom of a row/container
<div class="d-flex align-content-end flex-wrap mb-2">
<span class="display-4 fw-bold text-black text-start mt-0 mb-0">Active Mural Projects</span>
</div>