Bootstrap-4 card responsive image / text columns overlapping - html

I have 2 cards next to each other, I'm trying to design it such that they will always have the same height, and I'm having some trouble getting my left box to look nice with no overlap.
Currently I have two elements in the left box, an image element and a text element. I'm trying to style the left box such that the elements don't overlap and that the box is responsive when resized.
In my jsfiddle (https://jsfiddle.net/martinradio/jshet597/27/) it currently looks like this:
<br>
<div class="container-fluid">
<div class="row">
<!-- Left Box -->
<div class="col-md-4">
<div class="card mb-4 box-shadow" style=height:100%>
<div class="card-body ">
<div class="row align-items-center mb-4">
<div class="col">
<!-- Title -->
<h4 class="mb-2">
Left Box
</h4>
</div>
</div>
<div class="container h-100">
<div class=" justify-content-center align-items-center">
<div class="row ">
<!-- img -->
<div class="col-md-4">
<div class="">
<img class="img-fluid" src="https://www.kroger.com/product/images/medium/front/0004900005537" />
</div>
</div>
<!-- text -->
<div class="col-md-8 my-auto">
<div>INFO1:STUFFHERE</div>
<div>INFO2:MORESTUFFHERE</div>
<div>INFO3:EVENMORESTUFF,COOLHUH?</div>
</div>
</div> <!-- / .row -->
</div>
</div>
</div>
</div>
</div> <!-- /col -->
<!-- Right Box -->
<div class="col-md-8">
<div class="card mb-4 box-shadow" style=height:100%>
<div class="card-body">
<!-- Right Box -->
<div class="row align-items-center mb-4">
<div class="col">
<!-- Title -->
<h4 class="mb-2">
Right Box
</h4>
<!-- Subtitle -->
<p class="small text-muted mb-0">
Last Updated March 20, 2020
</p>
</div>
</div>
<!-- Top Row -->
<div class="row">
<!-- My Price -->
<div class="col-sm-2">
<h4 class="text-muted">My Price <span class="h4 fe fe-help-circle text-dark" data-toggle="tooltip" title="" data-original-title="Additional Info On My Price" ></span></h4>
</div>
<!-- Competitor Low Price -->
<div class="col-md-3 border-left">
<h4 class="text-muted">adasd <span class="h4 fe fe-help-circle text-dark" data-toggle="tooltip" title="" data-original-title="Additional Info On Competitor Low Price" ></span></h4>
<span class="h2 mb-0" id='competitiveLandscape_compLowPrice'>$1.29</span>
<br>
<h5 class="text-muted mt-1">z</h5>
</div>
<!-- Competitor High Price -->
<div class="col-md-3 border-left">
<h4 class="text-muted">ad <span class="h4 fe fe-help-circle text-dark" data-toggle="tooltip" title="" data-original-title="Additional Info On Competitor High Price" ></span></h4>
<span class="h2 mb-0" id='competitiveLandscape_compHighPrice'>$2.19</span>
<br>
<h5 class="text-muted mt-1">x</h5>
</div>
<!-- Competitor Price Index -->
<div class="col-md-3 border-left">
<h4 class="text-muted">sd <span class="h4 fe fe-help-circle text-dark" data-toggle="tooltip" title="" data-original-title="Additional Info On Competitor Price Index" ></span></h4>
<span class="h2 mb-0" id="competitiveLandscape_cpi">1.09</span>
<br>
<span id='cpiNumSpan' class="badge mt-n1"><i id='cpiNumIcon' class="fe "></i> 230 BPS</span>
</div>
</div>
<br>
<!-- Bottom Row -->
<div class="row">
<!-- Competitors -->
<div class="col-sm-2">
<h4 class="text-muted">df <span class="h4 fe fe-help-circle text-dark" data-toggle="tooltip" title="" data-original-title="Additional Info On Competitors" ></span></h4>
<span class="h2 mb-0" id='competitiveLandscape_competitors'>12</span>
<br>
<span class="badge badge-soft-danger mt-n1"><i class="fe fe-arrow-down"></i> 3</span>
</div>
<!-- Price Position -->
<div class="col-md-3 border-left">
<h4 class="text-muted">dfssdf <span class="h4 fe fe-help-circle text-dark" data-toggle="tooltip" title="" data-original-title="Additional Info On Price Position" ></span></h4>
<span class="h2 mb-0" id='competitiveLandscape_pricePosition'>3</span>
<br>
<span class="badge badge-soft-success mt-n1"><i class="fe fe-arrow-up"></i> 1</span>
</div>
<!-- Price Gap -->
<div class="col-md-3 border-left">
<h4 class="text-muted">sdfsdf <span class="h4 fe fe-help-circle text-dark" data-toggle="tooltip" title="" data-original-title="Additional Info On Price Gap" ></span></h4>
<span class="h2 mb-0" id='competitiveLandscape_priceGap'>35%</span>
<br>
<span class="badge badge-soft-danger mt-n1"><i class="fe fe-arrow-down"></i> 50 BPS</span>
</div>
<!-- Price Competitiveness -->
<div class="col-md-3 border-left">
<h4 class="text-muted">sdfsdf <span class="h4 fe fe-help-circle text-dark" data-toggle="tooltip" title="" data-original-title="Additional Info On Price Competitiveness" ></span></h4>
<span class="h2 mb-0" id='competitiveLandscape_priceCompetitiveness'>84%</span>
<br>
<span class="badge badge-soft-success mt-n1"><i class="fe fe-arrow-up"></i> 400 BPS</span>
</div>
</div>
</div>
</div>
</div>
</div> <!-- /row -->
</div>
Adding img-fluid helped with the responsiveness by preventing overlap, but has the side-effect of causing the image to appear very small, I tried to fix this by adding style="max-width:6" but it's not affecting the image.
The img-fluid tag has even caused the image / text to no longer be centered.
Is there a way I can get my img / text to stay aligned in the center of the card, with the image larger, while also retaining responsiveness so when it is resized there is no overlap?
Thanks

If I understand correctly, you want to center your left box, don't want to overlap content with image and keep your box height the same as the right side.
I removed .container, .row and .h-100 classes from your code and also removed some unwanted div from your code for getting a suitable result.
HERE IS YOUR CODE
https://jsfiddle.net/w5pzcxn6/

Related

Bootstrap 5 Vertical Alignment issue with responsive

I have a issue with vertical alignment in a container. I have the following code that does what I want, that is, the first row in the center and the second at the bottom of the container.
Full screen
<header class="masthead" id="home">
<div class="container h-100">
<div class="row h-100 align-items-center justify-content-evenly text-center">
<div class="col-4">
<img src="assets/img/profil.png" class="rounded-circle img-fluid" alt="...">
<hr class="divider" />
<h1 class="text-white font-weight-bold">d3vyce</h1>
</div>
<div class="col-md-8 col-lg-4">
<h2 class="text-white font-weight-bold">Hi 👋, Welcome to my Site!</h2>
<p class="text-white">Developer, CTF Player, Homelab, 3D Printing</p>
<hr class="divider" />
<div class="d-grid col-6 mx-auto">
<a class="btn btn-outline-light btn-lg" href="https://blog.d3vyce.fr" target="_blank"><i class="fa fa-bookmark fa-lg"></i> Blog</a>
<a class="btn mt-2 btn-outline-light btn-lg" href="https://github.com/d3vyce" target="_blank"><i class="fa fa-github fa-lg"></i> Github</a>
</div>
</div>
</div>
<div class="row head-row justify-content-center">
<div class="col-12 mouse_scroll p-0">
<a href="#about">
<div class="mouse">
<div class="wheel"></div>
</div>
<div>
<span class="m_scroll_arrows unu"></span>
<span class="m_scroll_arrows doi"></span>
<span class="m_scroll_arrows trei"></span>
</div>
</a>
</div>
</div>
</div>
</header>
For the alignment at the bottom of the second row I use the following CSS:
.mouse_scroll {
display: block;
width: 24px;
height: 100px;
position: absolute;
bottom: 0; }
The problem happens with the responsive. The columns of the first row are well one on top of the other, but the space between the two is much too important and I can't modify it :(
I tried to search on stackoverflow for answers, but after many tests I'm in a dead end...
Reponsive
Thank you in advance for your answers!

Bootstrap 4 collapse changes width of the page

I was working with bootstrap and found out a weird issue. When using collapse button, page width is changed (changes to lower), when I press collapse again to hide the shown content, page is reset to normal. What can be causing the issue?
<a class="btn btn-icon btn-light" data-toggle="collapse" href="#article-content1" role="button" aria-expanded="false" aria-controls="article-content1">
<i class="fas fa-minus"></i>
</a>
<div class="collapse" id="article-content1">
<div class="card-body">
You can show or hide this card.
</div>
<div class="card-footer">
<div class="container-fluid">
<div class="row">
<div class="col-1">
<img alt="image" src="./assets/img/avatar/avatar.png" class="rounded-circle avatar-outline ml-autox" alt="" width="46" height="46" style="margin-top:-3px">
</div>
<div class="col-6 text-left">
<strong>Jasmine Snow</strong></br>
<span class="color-muted">November 11, 2020</span>
</div>
<div class="col-5"><!-- empty --></div>
</div>
</div>
</div>
</div>

CSS moving button to right side

I am using bootstrap and angular material for the UI. In one of my div. I want to move my button to the right side but when I do apply class "float-right" it is going behind the other div.
This is the image URL https://prnt.sc/y0xn90
Below is the code.
<div class="card-body">
<div class="tab-content">
<!-- /.tab-pane -->
<div class="active tab-pane" id="timeline">
<div>
<button mat-raised-button color="primary">Add Treatment</button>
</div>
<div>
<ul class="timeline" *ngFor="let treatment of patientTreatments">
<li class="timeline-item bg-white rounded ml-3 p-4 shadow">
<div class="timeline-arrow"></div>
<h2 class="h5 mb-0">{{treatment.title}}<span class="float-right" style="cursor: pointer;">
<mat-icon>edit</mat-icon>
</span></h2>
<span class="small text-gray"><i class="fa fa-clock-o mr-1"></i>{{treatment.treatmentDate}}</span>
<p class="text-small mt-2 font-weight-light">{{treatment.summary}}</p>
<div *ngFor="let files of treatment.treatmentFiles">
<img src="" alt="Treatment image">
</div>
</li>
</ul><!-- End -->
</div>
<!-- The timeline -->
</div>
<!-- /.tab-pane -->
<div class="tab-pane" id="settings">
111
</div>
<!-- /.tab-pane -->
</div>
<!-- /.tab-content -->
</div><!-- /.card-body -->
you can use the display flex property with the width 100% and u can push left or right side with flex-end/flex-start
<div style="width: 100%;display: flex;justify-content: flex-end;align-items: center;">
<button mat-raised-button color="primary">Add Treatment</button>
</div>

Displaying items horizontally instead of columns

I need to make an index view for my posts, and I choose a photo gallery for that.In my controller I have paginate set at 10.Unfortunately, my column is divided by one, horizontally : https://imgur.com/a/8sUm5eb .
I want to make this to be divided by 2 columns, 5 items/column.Can you give me a little help with that?Thank you.
My view
<!-- Promo Block -->
<div class="container g-pt-100 g-pb-70">
<!-- News Section -->
<div class="u-heading-v3-1 g-mb-30">
<h2 class="h5 u-heading-v3__title g-color-gray-dark-v1 text-uppercase g-brd-primary">Latest News</h2>
</div>
#foreach($posts as $post)
<div class="masonry-grid-item col-sm-6 g-mb-30">
<!-- Blog Background Overlay Blocks -->
<article class="u-block-hover">
<div class="g-bg-cover g-bg-white-gradient-opacity-v1--after">
<img class="d-flex align-items-end u-block-hover__main--mover-down" src="/storage/{{ $post->image }}" alt="Image Description">
</div>
<div class="u-block-hover__additional--partially-slide-up text-center g-z-index-1 mt-auto">
<div class="u-block-hover__visible g-pa-25">
#foreach($post->tags as $tag)
<span class="g-color-white-opacity-0_7 g-font-size-10 text-uppercase">{{ $tag->name }}</span>
<span class="g-color-white-opacity-0_7 g-pos-rel g-top-2 mx-2">·</span>
#endforeach
<h2 class="h4 g-color-white g-font-weight-600 mb-3">
<a class="u-link-v5 g-color-white g-color-primary--hover g-cursor-pointer" href="/post/{{ $post->id }}">{{ $post->caption }}</a>
</h2>
<h4 class="d-inline-block g-color-white-opacity-0_7 g-font-size-11 mb-0">
By,
<a class="g-color-white-opacity-0_7 text-uppercase" href="/post/{{ $post->id }}">{{ $post->user->username }}</a>
</h4>
<span class="g-color-white-opacity-0_7 g-pos-rel g-top-2 mx-2">·</span>
<span class="g-color-white-opacity-0_7 g-font-size-10 text-uppercase">{{ $post->created_at->diffForHumans() }}</span>
<span class="g-color-white-opacity-0_7 g-pos-rel g-top-2 mx-2">·</span>
<span class="g-color-white-opacity-0_7 g-font-size-10 text-uppercase">{{ $post->comments()->count() }} comments</span>
</div>
<a class="d-inline-block g-brd-bottom g-brd-white g-color-white g-font-weight-600 g-font-size-12 text-uppercase g-text-underline--none--hover g-mb-30" href="/post/{{ $post->id }}">Read more</a>
</div>
</article>
<!-- End Blog Background Overlay Blocks -->
</div>
#endforeach
</div>
</div>
<!-- End News Section -->
Make your first foreach like this
<div class="row">
Your foreach
</div>

Bootstrap 4: Footer not at bottom

I know this question was probably asked some hundred times, but sadly no answer that I found in here really helped me.
I tried these answers for example:
Bootstrap footer not at bottom
Flushing footer to bottom of the page, twitter bootstrap
Height not 100% on Container Fluid even though html and body are
But I still have the problem that when my page content is to "small" and doesn't fill out the whole height of the body/page container the footer just floats somewhere above the end of the browser window.
This is the code for my footer:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
<footer class="d-flex justify-content-center">
<div class="d-flex justify-content-between col-md-8 col-md-offset-2 mb-3 mt-5">
<div class="align-left">
<a class="font-weight-bold small kf-blue kf-links" href="#">Link1</a> |
<a class="font-weight-bold small kf-blue kf-links" href="/">Link2</a> |
<a class="font-weight-bold small kf-blue kf-links" href="/">Link3</a>
</div>
<div class="align-right small">
Crafted with Love by <a class="font-weight-bold kf-blue kf-links" href="#" target="_blank">Me</a>
</div>
</div>
</footer>
I'm using Bootstrap 4.1 and Chrome, here's also a codepen to my site:
https://codepen.io/anon/pen/oMZVxq
Note: you have to use the sidebar view in codepen to actually see that the footer is not at the bottom, as the view size in codepen is so small that it looks correctly.
You can use built-in bootstrap class to achieve this.
What you need is the container to be a column flex container . class to use are : d-flex flex-column
To set the container to height:100% you can apply the class h-100to html, body and the container or add to the container style height:100vh;
For the footer, a margin-top:auto will do, the class to use is : mt-auto;
example below to run in full page mode
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<html class="h-100">
<body class="h-100">
<!-- Page Container -->
<div id="page-container" class="container-fluid pr-0 pl-0 h-100 d-flex flex-column">
<!-- Header -->
<nav class="navbar navbar-expand-lg navbar-light bg-light pt-3 pb-3 d-flex justify-content-center">
<div class="col-md-8 col-lg-8 col-sm-12 col-xs-12 d-flex justify-content-between">
<div class="d-flex justify-content-start align-items-center">
<a href="/" class="kf-links">
<span class="h5">
<i class="fas fa-paper-plane"></i>
<span class="h4 font-weight-bold kf-dark">
MyPage
</span>
</span>
</a>
</div>
<!-- Main Header Navigation -->
<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
<ul class="navbar-nav">
<li class="nav-item">
Link1
</li>
<li class="nav-item">
Link2
</li>
<li class="nav-item">
Link3
</li>
</ul>
</div>
<!-- END Main Header Navigation -->
</div>
</nav>
<!-- END Header -->
<!-- Main Container -->
<div style="background:#5c90d2">
<div class="col-md-12 text-center pt-5 pb-5">
<div class="pt-5 pb-5">
<h1>
<span class="main-text">
Login
</span>
</h1>
<p class="lead"><span class="main-text">
Login Now!
</span></p>
</div>
</div>
</div>
<!-- Content -->
<div class="d-flex justify-content-center fadeIn">
<div class="col-md-8 col-xs-12">
<div class="d-flex justify-content-center">
<div class="col-md-6 pt-5 pb-5 pr-0 pl-0">
<form class="form-horizontal" method="post">
<div class="form-group">
<div class="col-xs-12">
<div class="">
<label for="id_username">E-Mail</label>
<input id="id_username" class="form-control" maxlength="254" name="username" value="" type="text" required>
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
<div class="">
<label for="id_password">Password</label>
<input id="id_password" class="form-control" name="password" type="password" required>
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
<small class="float-right">
Forgot Password?
</small>
</div>
</div>
<div class="form-group mt-5">
<div class="col-xs-12 col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-4 pl-0">
<button class="btn btn-sm btn-block btn-primary" type="submit">Login</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- END Content -->
<!-- END Main Container -->
<!-- Footer -->
<footer class="d-flex justify-content-center mt-auto">
<div class="d-flex justify-content-between col-md-8 col-md-offset-2 mb-3 mt-5">
<!-- Copyright Info -->
<div class="align-left">
<a class="font-weight-bold small kf-blue kf-links" href="#">Link1</a> |
<a class="font-weight-bold small kf-blue kf-links" href="/">Link2</a> |
<a class="font-weight-bold small kf-blue kf-links" href="/">Link3</a>
</div>
<div class="align-right small">
Crafted with Love by <a class="font-weight-bold kf-blue kf-links" href="#" target="_blank">Me</a>
</div>
<!-- END Copyright Info -->
</div>
</footer>
<!-- END Footer -->
</div>
<!-- END Page Container -->
</body>
</html>
codepen updated https://codepen.io/anon/pen/PBpgNN
reminder for boostrap classes https://getbootstrap.com/docs/4.5/utilities/flex/ about sizing see https://getbootstrap.com/docs/4.5/utilities/sizing/
If you want a fixed footer, just add the class fixed-bottom to the footer tag like shown below.
<footer class="fixed-bottom bg-dark">
<div class="text-center">
<p>Footer</p>
</div>
</footer>
First add display: flex; and flex-direction: column; to #page-container.
Now you have "set the stage" for aligning the footer to the bottom. Set its margin-top to auto (by adding the class mt-auto) and you are done;
<div class="d-flex justify-content-center mt-auto">
Content here
</div>
See this codepen.
So this helped me - if someone is still looking for an answer:
on your <HTML>, <body> and your container div add a class h-100 and your footer will stay on the bottom.
Important
One thing I did to remove the extra height is that on my container div I changed the h-100 styling to height: calc(100% - 200px) !important; (where -200px was the height of my navigation and footer)
if you are not using the bootstrap, here is the styling .h-100{height:100% !important}