I am trying to align images with Bootstrap 4. I've used .row within a .container. I now have whitespace between images and I don't want it to be that way. I want the images aligned immediately next to each other without any spaces. Any suggestions would be appreciated.
<div class="container mycontainer">
<div class="row">
<div class="col-sm-12 col-md-6 col-lg-6" id="one"> <!-- FIRST ROW LEFT SIDE-->
<img src="./images-for-sample/images-for-sample/investors-img-1.jpg" alt="" class="img-responsive" id="photo-1">
</div>
<div class="col-sm-12 col-md-6 col-lg-6" id="two"> <!-- FIRST ROW RIGHT SIDE-->
<img src="./images-for-sample/images-for-sample/investors-img-4.jpg" alt="" class="img-responsive" id="photo-4">
</div>
</div>
<div class="row">
<div class="col-sm-12 col-md-6 col-lg-6" id="three"> <!-- SECOND ROW LEFT SIDE-->
<img src="./images-for-sample/images-for-sample/investors-img-2.jpg" alt="" class="img-responsive" id="photo-2">
</div>
<div class="col-sm-12 col-md-6 col-lg-6" id="four"> <!-- SECOND ROW RIGHT SIDE-->
<img src="./images-for-sample/images-for-sample/investors-img-5.jpg" alt="" class="img-responsive" id="photo-5">
</div>
</div>
<div class="row">
<div class="col-sm-12 col-md-6 col-lg-6" id="five"> <!-- THIRD ROW LEFT SIDE-->
<img src="./images-for-sample/images-for-sample/investors-img-3.jpg" alt="" class="img-responsive" id="photo-3">
</div>
<div class="col-sm-12 col-md-6 col-lg-6" id="six"> <!-- THIRD ROW RIGHT SIDE-->
<img src="./images-for-sample/images-for-sample/investors-img-6.jpg" alt="" class="img-responsive" id="photo-6">
</div>
</div>
</div>
The output I get currently is:
In order to achieve your targeted goal you have to remove Bootstrap's paddings for each div and set the images width to 100% of those:
// you could also use img as a selector
.img-responsive {
width: 100%;
}
// this is the selector of your div's
.col-sm-12 {
padding: 0;
}
However, due to your current implementation this would result in the following (for a running fiddle click here):
If you additionally want to remove the whitespaces shown in the image, you could use Bootstrap's card columns like this:
<div class="card-columns">
<div class="card" id="one"> <!-- FIRST ROW LEFT SIDE-->
<img src="https://via.placeholder.com/350x200" alt="" class="img-responsive" id="photo-1">
</div>
<div class="card" id="two"> <!-- FIRST ROW RIGHT SIDE-->
<img src="https://via.placeholder.com/350x150" alt="" class="img-responsive" id="photo-4">
</div>
<div class="card" id="three"> <!-- SECOND ROW LEFT SIDE-->
<img src="https://via.placeholder.com/350" alt="" class="img-responsive" id="photo-2">
</div>
<div class="card" id="four"> <!-- SECOND ROW RIGHT SIDE-->
<img src="https://via.placeholder.com/350x450" alt="" class="img-responsive" id="photo-5">
</div>
<div class="card" id="five"> <!-- THIRD ROW LEFT SIDE-->
<img src="https://via.placeholder.com/350" alt="" class="img-responsive" id="photo-3">
</div>
<div class="card" id="six"> <!-- THIRD ROW RIGHT SIDE-->
<img src="https://via.placeholder.com/350" alt="" class="img-responsive" id="photo-6">
</div>
</div>
and adjust it with some css to your need:
// the default column count is 1 and there should not be a space between the columns
.card-columns {
column-count: 1;
column-gap: 0;
}
// for medium devices and larger set the count to two
#media (min-width: 768px) {
.card-columns {
column-count: 2;
}
}
// reset card's margin bottom
.card {
margin: 0 !important;
}
// scale images properly to fit the divs
img {
width: 100%;
max-width: 100%;
}
The result looks like this:
You can find the running fiddle here.
If you are using Bootstrap 3, have a look at this Medium article.
Good luck!
Related
In this code i am preparing a portfolio, now when i am placing an
image in my portfolio the image is not filling the border div and
going a side as you can see in the picture <IMAGE-first half> , <IMAGE-second half>. Can someone help me to keep four images that has borders only to the image and I need all four images placed like four boxes?
<section class="latestwork" id="work">
<div class="container">
<div class="row">
<div class="heading">
<h2 class="boxx">My Latest Work</h2>
<h6>These are my latest mobile photography captures</h6>
</div>
</div>
<div class="row">
<div class="myworkbuttons">
<button type="button" class="myworklink" data-filter="all">All</button>
<button type="button" class="myworklink" data-filter="creative">Creative</button>
<button type="button" class="myworklink" data-filter="black&white">Black/white</button>
<button type="button" class="myworklink" data-filter="portrait">Portraits</button>
</div>
</div>
<div class="row">
<div class="portfolio-items" data-category="urban-floods">
<div class="portfolio-inner-item" style="">
<div class="portfolio-img">
<img src="C:\portfolio's\drive-download-20210208T164603Z-001\The Disaster of 2020.jpg" alt="Image not loading">
</div>
</div>
<div class="portfolio-info">
<h4>Iso: </h4>
</div>
</div>
<div class="portfolio-items" data-category="buffalo">
<div class="portfolio-inner-item">
<div class="portfolio-img">
<img src="C:\portfolio's\drive-download-20210208T164603Z-001\buffalos path.jpg" style="float: left;" alt="Image not loading">
</div>
</div>
</div>
</div>
This is happening because the size of the image is not big enough.
Try adding width: 100% of the image component.
you can use grid and and use css importing file and try this code: .div{background-image: url("/assets/pics/picture.jpg"); background-position: center; background-repeat: no-repeat; background-size: cover; min-height:50vh; min-width:50vw }//(or what size do you need.);
I have a page that displays a lot of divs, in 2 by x grid.. this is the code:
<div class="row d-flex justify-content-around" >
#foreach(auth()->user()->galleries as $gallery)
<div class="col-5
mb-5
p-3
rounded-lg
shadow
d-flex
justify-content-between
align-items-baseline
"
style="background-color: lightgrey;
background-size: 100%;
background-position: center;">
<div class="w-75">
<div class="">
<h2>{{$gallery->galname}}</h2>
</div>
<div class="">
SOME CONTENT...
</div>
</div>
<div class="my-auto">
<div class="d-flex justify-content-around p-1">
<button class="btn btn-primary" type="button" onclick="window.location='/gallery/{{ $gallery->id }}'">View / Edit</button>
</div>
</div>
</div>
#endforeach
</div>
So far it works great, but if i reduce the size of the browser or watch it on a cellphone, then they squish toghether.. I would like it to be responsive and jump to the next row if there is not enoguh space available.. so the 2 by x becomes a 1 by 2x table... how can this be done?
You may add classes for the responsive design after col-5, i.e. col-sm-10 which will change the size of the div in small screens.
.... class="col-5 col-sm-10 mb-5 ...
more info here
My code:
.items {
display: grid;
grid-template-columns: repeat(3, 1fr);
box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.3);
}
How can I properly display my images as a 3 column grid?
<section id="work-a" class="text-center py-3">
<div class="container">
<h2 class="section-title">My Work</h2>
<div class="bottom-line"></div>
<p class="lead">
Check out some of my projects
</p>
<div class="items">
<div class="item">
<div class="item-image">
<img src="img/items/item1.png" alt="">
</div>
<div class="item-text">
<div class="item-text-wrap">
<p class="item-text-category">Design</p>
<h2 class="item-text-title">Great Gradients</h2>
</div>
</div>
</div>
<div class="item">
<div class="item-image">
<img src="img/items/item2.png" alt="">
</div>
<div class="item-text">
<div class="item-text-wrap">
<p class="item-text-category">Design</p>
<h2 class="item-text-title">Great Gradients</h2>
</div>
</div>
</div>
<div class="item">
<div class="item-image">
<img src="img/items/item3.png" alt="">
</div>
<div class="item-text">
<div class="item-text-wrap">
<p class="item-text-category">Design</p>
<h2 class="item-text-title">Great Gradients</h2>
</div>
</div>
</div>
</div>
</div>
</section>
I have made the following grid in Bootstrap 4:
<div class="container-fluid">
<div class="row padding">
<div id="workshop1" class="col-lg-6 nopadding">
<img src="images/Werkstatt/image_05.jpg" class="img-fluid nopadding" alt="">
</div>
<div class="col-lg-6">
<div class="row">
<div id="workshop2" class="col-lg-6 nopadding">
<img src="images/Werkstatt/image_06.jpg" class="img-fluid nopadding" alt="">
</div>
<div id="workshop3" class="col-lg-6 nopadding">
<img src="images/Werkstatt/image_08.jpg" class="img-fluid nopadding" alt="">
</div>
</div>
<div class="row">
<div id="workshop4" class="col-lg-6 nopadding">
<img src="images/Werkstatt/image_09.jpg" class="img-fluid nopadding" alt="">
</div>
<div id="workshop5" class="col-lg-6 nopadding">
<img src="images/Werkstatt/image_07.jpg" class="img-fluid nopadding" alt="">
</div>
</div>
</div>
</div> <!-- end of first row -->
<div class="row padding">
<div id="workshop6" class="col-lg-3 nopadding">
<img src="images/Werkstatt/image_01.jpg" class="img-fluid nopadding" alt="">
</div>
<div id="workshop7" class="col-lg-3 nopadding">
<img src="images/Werkstatt/image_04.jpg" class="img-fluid nopadding" alt="">
</div>
<div id="workshop8" class="col-lg-3 nopadding">
<img src="images/Werkstatt/image_02.jpg" class="img-fluid nopadding" alt="">
</div>
<div id="workshop9" class="col-lg-3 nopadding">
<img src="images/Werkstatt/image_03.jpg" class="img-fluid nopadding" alt="">
</div>
</div> <!-- end of second row -->
</div>
The css file looks like this:
.nopadding {
padding-left: 0;
padding-right: 0;
}
Now I have the problem, that there is a small white line between the right part of row 2 and row 3 in Safari and Chrome on my Mac. In Firefox everything looks fine:
Firefox
Chrome & Safari
Does anybody have an idea how fix this? All browsers are up to date.
Thanks in advance.
Regards
Lars
Try adding display: block; to your images or float: left;
Sometimes trying font-size: 0; or line-height: 0; works.
I have difficulties to add border to the last class="separator" from the last class="list-group".
I want to do this in SASS. Can someone please help me, because my solution doesn't work.
HTML
<div class="list-group">
<div class="list-group-item"></div>
<div class="separator"></div>
</div>
<div class="list-group">
<div class="list-group-item"></div>
<div class="separator"></div>
</div>
<div class="list-group">
<div class="list-group-item"></div>
<div class="separator"></div>
</div>
<div class="list-group">
<div class="list-group-item"></div>
<div class="separator"></div>
</div>
CSS
.list-group {
&:last-child .separator {
border-left: 1px solid black;
}
}
According to me there is no problem in your sass code. Just add some content into html and the browser will start showing border. Something like this
<div class="list-group">
<div class="list-group-item"></div>
<div class="separator">item1</div>
</div>
<div class="list-group">
<div class="list-group-item"></div>
<div class="separator">item2</div>
</div>
<div class="list-group">
<div class="list-group-item"></div>
<div class="separator">item3</div>
</div>
<div class="list-group">
<div class="list-group-item"></div>
<div class="separator">item4</div>
</div>
Output (for your reference):
can you spot the left border on item4?
This worked for me.
I know it's too late xd
.list-group {
.separator:last-child {
border-left: 1px solid black;
}
}