Different height and position for col in bootstrap [duplicate] - html

This question already has answers here:
CSS-only masonry layout
(4 answers)
Closed 3 years ago.
I wrote this code for insert image in order to create a grid full of photos:
<section class="gallery-section">
<div class="container grid-custom" style="padding-top: 50px;">
<div class="row">
<div style="padding: 0px;" class="text-center col-md-4 gallery-image">
<img src="./images/cover.jpg" alt="" class="img-fluid">
</div>
<div style="padding: 0px;" class="my-auto text-center col-md-4 gallery-image">
<img src="./images/passero.jpg" alt="" class="img-fluid">
</div>
<div style="padding: 0px;" class="text-center col-md-4 gallery-image">
<img src="./images/cigno.JPG" alt="" class="img-fluid">
</div>
</div>
<div class="row">
<div style="padding: 0px;" class="text-center col-md-4 gallery-image">
<img src="./images/pic1.jpg" alt="" class="img-fluid">
</div>
<div style="padding: 0px;" class="text-center col-md-4 gallery-image">
<img src="./images/fiore.JPG" alt="" class="img-fluid">
</div>
<div style="padding: 0px;" class="text-center col-md-4 gallery-image">
<img src="./images/sfondo7.jpg" alt="" class="img-fluid">
</div>
</div>
</div>
</section>
But I get this result:
What should I do instead to get a result like this?

You are placing 3 images per div.row, which results in this layout:
As you can see, the div.row elements are stacked, and each div.row is as high as its highest image, creating gaps for the remaining space in each row.
In summary, you have divided the grid first by rows, and then by columns.
What you need is a masonry grid. As opposite to your approach, this grid is divided first by columns, and then by rows or images.
The main concept behind a masonry grid resides in an approach like this:
<!-- Left column -->
<div class="col-md-4">
<img src="" alt="Top image">
<img src="" alt="Middle image">
<img src="" alt="Bottom image">
</div>
<!-- Center column -->
<div class="col-md-4">
<img src="" alt="Top image">
<img src="" alt="Middle image">
<img src="" alt="Bottom image">
</div>
<!-- Right column -->
<div class="col-md-4">
<img src="" alt="Top image">
<img src="" alt="Middle image">
<img src="" alt="Bottom image">
</div>

What you are looking for is a Masonry Layout.
There are a lot of websites that give nice tutorials. Here for instance I would refer to https://css-tricks.com/piecing-together-approaches-for-a-css-masonry-layout/

Related

How to fix equal column the height problem in bootstrap [duplicate]

This question already has answers here:
CSS-only masonry layout
(4 answers)
Closed 2 years ago.
I'm new to bootstrap. I'm trying to create a gallery of some amazing arts. But, I'm facing some issues. All of the columns are taking up equal height even though the image isn't that large. How can I remove the extra space?
<div class="container-fluid">
<div class="row content" id="images">
<div class="col-md-4">
<img src="..\images\allyson-beaucourt-HaD6zYONkg0-unsplash.jpg" alt="" class="img-fluid">
</div>
<div class="col-md-4">
<img src="..\images\annie-spratt-52hSxHwXE7I-unsplash.jpg" alt="" class="img-fluid">
</div>
<div class="col-md-4">
<img src="..\images\amr-taha-ig_Qc8qoTSI-unsplash.jpg" alt="" class="img-fluid">
</div>
<div class="col-md-4">
<img src="..\images\annie-spratt-Pzyyzaiy-LE-unsplash.jpg" alt="" class="img-fluid">
</div>
<div class="col-md-4">
<img src="..\images\arno-senoner-FOM8031NAG8-unsplash.jpg" alt="" class="img-fluid">
</div>
<div class="col-md-4">
<img src="..\images\bp-miller-f6BffCg5Ymc-unsplash.jpg" alt="" class="img-fluid">
</div>
</div>
</div>
this is how I want it to look.
This can be helpful
<div class="container-fluid">
<div class="row">
<div class="col-md-6 content" id="images">
<div class="col-md-12 ">
<img src="..\images\allyson-beaucourt-HaD6zYONkg0-unsplash.jpg" alt="" class="img-fluid">
</div>
<div class="col-md-12 ">
<img src="..\images\annie-spratt-52hSxHwXE7I-unsplash.jpg" alt="" class="img-fluid">
</div>
<div class="col-md-12 ">
<img src="..\images\amr-taha-ig_Qc8qoTSI-unsplash.jpg" alt="" class="img-fluid">
</div>
</div>
<div class="col-md-6 content" >
<div class="col-md-12 " style="max-height: 50%">
<img src="..\images\annie-spratt-Pzyyzaiy-LE-unsplash.jpg" alt="" class="img-fluid">
</div>
<div class="col-md-12 " style="max-height: 50%">
<img src="..\images\arno-senoner-FOM8031NAG8-unsplash.jpg" alt="" class="img-fluid">
</div>
</div>
</div>
see more on bootstrap grid

How to increase height of first row image in bootstrap

I want to design like this in bootstrap css , picture
What i have tried is
<div class="row">
<div class="col-md-3">
<img class="img-responsive" src="img1.jpg">
</div>
<div class="col-md-6">
<img class="img-responsive" src="img3.jpg">
</div>
<div class="col-md-3">
<img class="img-responsive" src="img5.jpg">
</div>
<div class="col-md-3">
<img class="img-responsive" src="img2.jpg">
</div>
<div class="col-md-6">
<img class="img-responsive" src="img4.jpg">
</div>
<div class="col-md-3">
<img class="img-responsive" src="img6.jpg">
</div>
</div>
The height of images img1.jpg,img4.jpg,img5.jpg need to increase as shown in image attcahed,
Is there any Experts in CSS?
Add the .img-fluid class to each of your images so they scale with the parent div's. That should work.
https://getbootstrap.com/docs/4.0/content/images/#responsive-images
You can achieve the desired layout with modification on your html code. Try this code.
<div class="row">
<div class="col-md-3">
<img class="img-responsive" src="img1.jpg">
<br>
<img class="img-responsive" src="img2.jpg">
</div>
<div class="col-md-6">
<img class="img-responsive" src="img3.jpg">
<br>
<img class="img-responsive" src="img4.jpg">
</div>
<div class="col-md-3">
<img class="img-responsive" src="img5.jpg">
<br>
<img class="img-responsive" src="img6.jpg">
</div>
</div>

Bootstrap Image Grid [duplicate]

This question already has answers here:
Bootstrap 4 masonry layout utilizing flexbox grid
(3 answers)
Closed 4 years ago.
I want to create a responsive image grid as in the picture below:
How do I use bootstrap columns and rows to achieve this?
<div class="row">
<div class="col-md-3 sm-12"
<img class="img-thumbnail" scr=".......">
</div>
<div class="col-md-3 sm-12"
<img class="img-thumbnail" scr=".......">
</div>
<div class="col-md-3 sm-12"
<img class="img-thumbnail" scr=".......">
</div>
........
...........
.................
.....................
</div>
I place all the columns inside a single row so that the column elements wrap themselves but this does not happen.
When I implement the code above, due to "height: auto" some images are long and this creates void white space between images of different rows.
I get something like this as a result:
You can achieve this with card columns. JSFiddle here:
<div class="container-fluid pt-3">
<div class="card-columns">
<div class="card">
<img class="card-img-top" style="width:100%; height: 200px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 500px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 300px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 400px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 400px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 300px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 500px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 200px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 200px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 500px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 300px;"/>
</div>
<div class="card">
<img class="card-img-top" style="width:100%; height: 400px;"/>
</div>
</div>
</div>
depending on you requirement, you need to replace col-3 with col-sm-3 or col-md-3, etc:
img
{
width: 100%;
margin: 10px 0px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="row">
<div class="col-3">
<img src="https://www.w3schools.com/w3images/nature.jpg" alt="Lights" >
<img src="https://www.w3schools.com/w3images/falls2.jpg" alt="Lights" >
<img src="https://www.w3schools.com//w3images/wedding.jpg"alt="Lights" >
</div>
<div class="col-3">
<img src="https://www.w3schools.com/w3images/rocks.jpg" alt="Lights" >
<img src="https://www.w3schools.com/w3images/fjords.jpg" alt="Lights" >
</div>
<div class="col-3">
<img src="https://www.w3schools.com/w3images/fjords.jpg" alt="Lights" >
<img src="https://www.w3schools.com/w3images/lights.jpg" alt="Lights" >
<img src="https://www.w3schools.com//w3images/wedding.jpg"alt="Lights" >
</div>
<div class="col-3">
<img src="https://www.w3schools.com/w3images/nature.jpg" alt="Lights" >
<img src="https://www.w3schools.com//w3images/rocks.jpg" alt="Lights" >
</div>
</div>
I don't think that's possible with just bootstrap.
Look for the masonry ( https://masonry.desandro.com/ ) or isotope ( https://isotope.metafizzy.co/ ) plugin for bootstrap.

displaying 3 images in a row with text underneath in bootstrap

I am trying to display 3 images in a row with a title, some text underneath the title and a button. I have tried doing this in bootstrap only to get the text moving all over the place. This seems like the only way I could get the text to stay put, but now as you can see my images are stacked on top of each other rather than next to each other. Any help would be appreciated!
<section class="part2">
<div class="container">
<div class="row">
<div class="text-center">
<img alt="" class="resize-image" id="image1" src="/wp-content/themes/creativeforces/images/kid2.jpg">
<p>Teach</p>
<img alt="" class="resize-image" id="image2" src="/wp-content/themes/creativeforces/images/kid2.jpg">
<p>Read</p>
<img alt="" class="resize-image" id="image3" src="/wp-content/themes/creativeforces/images/kid2.jpg">
<p>Play</p>
</div>
</div>
</div>
this is what it looks like now
i am trying to get it to look something like this
You will need to add grids to your rows. This should work
<section class="part2">
<div class="container">
<div class="row">
<div class="col-md-4">
<img alt="" class="resize-image center-block" id="image1" src="/wp-content/themes/creativeforces/images/kid2.jpg" />
<p class="text-center">Teach</p></div>
<div class="col-md-4"><img alt="" class="resize-image center-block" id="image2" src="/wp-content/themes/creativeforces/images/kid2.jpg" />
<p class="text-center">Read</p></div>
<div class="col-md-4"><img alt="" class="resize-image center-block" id="image3" src="/wp-content/themes/creativeforces/images/kid2.jpg" />
<p class="text-center">Play</p></div>
</div>
</div>
</section>
Please use this example. You need to use bootstrap grid classes like "col-md-x" where x is number from 1 to 12.
<section class="part2">
<div class="container">
<div class="row">
<div class="col-md-4 text-center">
<img alt="" class="resize-image" id="image2" src="/wp-content/themes/creativeforces/images/kid2.jpg">
<p>Read</p>
</div>
<div class="col-md-4 text-center">
<img alt="" class="resize-image" id="image1" src="/wp-content/themes/creativeforces/images/kid2.jpg">
<p>Teach</p>
</div>
<div class="col-md-4 text-center">
<img alt="" class="resize-image" id="image3" src="/wp-content/themes/creativeforces/images/kid2.jpg">
<p>Play</p>
</div>
</div>

Creating a responsive row

I'm trying to create a responsive row that, when displayed on an iPad, the 3 images go across the screen like on desktop. Currently they are behaving like they are on mobile and expanding vertically, not horizontally.
The images are the 3 product range images on the website: http://dekatest.neto.com.au/
<div class="container" style="text-align:center;">
<div class="row"><img alt="" src="/assets/images/MEDICAL-RANGE.jpg" style="max-width:100%;" /><img alt="" src="/assets/images/SPROTS-RANGE.jpg" style="max-width:100%;" /><img alt="" src="/assets/images/WELLBEING-RANGE.jpg" style="max-width:100%;" /></div>
</div>
If you are using Bootstrap try something like this
<div class="container text-center">
<div class="row">
<div class="col-sm-4">
<img alt="" src="/assets/images/MEDICAL-RANGE.jpg" />
</div>
<div class="col-sm-4">
<img alt="" src="/assets/images/SPROTS-RANGE.jpg" />
</div>
<div class="col-sm-4">
<img alt="" src="/assets/images/WELLBEING-RANGE.jpg" />
</div>
</div>
</div
and with CSS add the properties and styles to your tags
img { max-width: 100%; }
Note: you should change the value of col-sm-* depending on what you are trying to do.
if you are only using row just because of that you don't need padding between images. So simple is that make separate class for controlling padding of col-sm. You should have to use col-* inside row then it will be work fine.
CSS
.no-p{
padding-left:0px;
paddding-right:0px;
}
HTML
<div class="container text-center">
<div class="row">
<div class="col-xs-4 no-p">
<img class="img-responsive" alt="" src="https://placeholdit.imgix.net/~text?txtsize=47&txt=500%C3%97500&w=500&h=500" />
</div>
<div class="col-xs-4 no-p">
<img class="img-responsive" alt="" src="https://placeholdit.imgix.net/~text?txtsize=47&txt=500%C3%97500&w=500&h=500" />
</div>
<div class="col-xs-4 no-p">
<img class="img-responsive" alt="" src="https://placeholdit.imgix.net/~text?txtsize=47&txt=500%C3%97500&w=500&h=500" />
</div>
</div>
</div>
View on JsFiddle: https://jsfiddle.net/L2y3ybff/