i was using bootstrap grid system to format picture like:
this is my code :
<div class="row">
<div class="col-md-4">
<div class="well"><img src="..." class="img-responsive"">
<br/>
<br/>
<br/>
<br/>
<br/>
</div>
</div>
<div class="col-md-8">
<div class="row">
<div class="col-md-6">
<div class="well"><img src="..." class="img-responsive" alt="Responsive image"></div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="well"><img src="..." class="img-responsive" alt="Responsive image"></div>
</div>
</div>
</div>
</div>
I want the picture to be responsive so I put class="img-responsive" on the <img>
<img src="..." class="img-responsive" alt="Responsive image">
but end up like the right picture. if i dont use class="img-responsive" the image will show on full resulution. how i fix this? (please give me a easy explanation because i'm a noob :) )
You can apply CSS Flexbox rules on .row & .col-*-*. I've used some custom classes (all the .col-*-* has a class called .item). Like:
.row {
display: flex;
}
.item {
display: flex;
flex-direction: column;
}
.item.left {
flex-direction: row;
}
Have a look at the snippet below:
.row {
display: flex;
}
.item {
display: flex;
flex-direction: column;
}
.item.left {
flex-direction: row;
}
.item.left .well {
width: 100%;
align-self: stretch;
}
.item.left .well img {
height: 100%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="item left col-sm-4">
<div class="well"><img src="http://placehold.it/200x200" class="img-responsive">
</div>
</div>
<div class="item col-sm-8">
<div class="row">
<div class="col-sm-6">
<div class="well"><img src="http://placehold.it/100x100" class="img-responsive" alt="Responsive image"></div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="well"><img src="http://placehold.it/100x100" class="img-responsive" alt="Responsive image"></div>
</div>
</div>
</div>
</div>
Hope this helps!
You should use following HTML structure as you need left and right columns having equal width:
<div class="container">
<div class="row">
<div class="col-xs-6">
// content....
</div>
<div class="col-xs-6">
// content....
</div>
</div>
</div>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-xs-6">
<div class="well"><img src="..." class="img-responsive">
<br>
<br>
<br>
<br><br>
</div>
</div>
<div class="col-xs-6">
<div class="well"><img src="..." class="img-responsive" alt="Responsive image"></div>
<div class="well"><img src="..." class="img-responsive" alt="Responsive image"></div>
</div>
</div>
</div>
Related
I got a horizontal scrolling page with bootstrap 5. All images have the same height, but different widths. My goal is that the images always use the full width of the page, so when the browser window is resized the images should shrink too.
What am I missing to achieve this? Your help is highly appreciated.
.container-fluid{
/* Vertical Scroll */
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
height: 100%;
}
.flex-nowrap {
-webkit-flex-wrap: nowrap!important;
-ms-flex-wrap: nowrap!important;
flex-wrap: nowrap!important;
}
.row {
flex-direction: column;
}
.col > img {
min-height: 100px;
max-height: 300px;
height: 300px;
padding-right:10px;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid ">
<div class="row flex-row d-flex flex-nowrap">
<div class="col">
<img src="https://via.placeholder.com/450x600.png" alt="">
</div>
<div class="col">
<img src="https://via.placeholder.com/500x600.png" alt="">
</div>
<div class="col">
<img src="https://via.placeholder.com/550x600.png" alt="">
</div>
<div class="col">
<img src="https://via.placeholder.com/333x600.png" alt="">
</div>
<div class="col">
<img src="https://via.placeholder.com/450x600.png" alt="">
</div>
<div class="col">
<img src="https://via.placeholder.com/500x600.png" alt="">
</div>
<div class="col">
<img src="https://via.placeholder.com/550x600.png" alt="">
</div>
<div class="col">
<img src="https://via.placeholder.com/333x600.png" alt="">
</div>
<div class="col">
<img src="https://via.placeholder.com/450x600.png" alt="">
</div>
<div class="col">
<img src="https://via.placeholder.com/500x600.png" alt="">
</div>
<div class="col">
<img src="https://via.placeholder.com/550x600.png" alt="">
</div>
<div class="col">
<img src="https://via.placeholder.com/333x600.png" alt="">
</div>
</div>
</div>
If you want the children of .flex-row to have their widths determined by the image, you need to replace .col with .w-auto.flex-shrink-1.flex-grow-1 and add .img-fluid to your images. You have some errors in your stylesheet as well. Take a look at the snippet:
EDIT
If you are looking for vertical responsiveness (not what people typically mean) then use the unit vh on the height setting and don't use .flex-shrink-1. This will make the images a percentage of the viewport height while maintaining aspect ratio. Take a look at the updated snippet using height: 30vh; and min-height: 100px;:
.container-fluid {
/* Vertical Scroll */
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
height: 100%;
}
.flex-nowrap {
-webkit-flex-wrap: nowrap !important;
-ms-flex-wrap: nowrap !important;
flex-wrap: nowrap !important;
}
/* .row {
flex-direction: column;
} */
.w-auto>img {
min-height: 100px;
/* max-height: 300px; */
height: 30vh;
padding-right: auto;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid ">
<div class="row flex-row d-flex flex-nowrap">
<div class="w-auto flex-grow-1">
<img src="https://via.placeholder.com/450x600.png" class="img-fluid" alt="">
</div>
<div class="w-auto flex-grow-1">
<img src="https://via.placeholder.com/500x600.png" class="img-fluid" alt="">
</div>
<div class="w-auto flex-grow-1">
<img src="https://via.placeholder.com/550x600.png" class="img-fluid" alt="">
</div>
<div class="w-auto flex-grow-1">
<img src="https://via.placeholder.com/333x600.png" class="img-fluid" alt="">
</div>
<div class="w-auto flex-grow-1">
<img src="https://via.placeholder.com/450x600.png" class="img-fluid" alt="">
</div>
<div class="w-auto flex-grow-1">
<img src="https://via.placeholder.com/500x600.png" class="img-fluid" alt="">
</div>
<div class="w-auto flex-grow-1">
<img src="https://via.placeholder.com/550x600.png" class="img-fluid" alt="">
</div>
<div class="w-auto flex-grow-1">
<img src="https://via.placeholder.com/333x600.png" class="img-fluid" alt="">
</div>
<div class="w-auto flex-grow-1">
<img src="https://via.placeholder.com/450x600.png" class="img-fluid" alt="">
</div>
<div class="w-auto flex-grow-1">
<img src="https://via.placeholder.com/500x600.png" class="img-fluid" alt="">
</div>
<div class="w-auto flex-grow-1">
<img src="https://via.placeholder.com/550x600.png" class="img-fluid" alt="">
</div>
<div class="w-auto flex-grow-1">
<img src="https://via.placeholder.com/333x600.png" class="img-fluid" alt="">
</div>
</div>
</div>
I'm using Bootstrap and trying to make 3 images to be centered. For example, red color boxes are how my images look like, and I want to make it look like blue color boxes:
I tried getting rid of the margin and padding, but I still want some space between the images. Also I tried using { display: table; }, display: table-cell; vertical-align: middle; but somehow it does not do anything to my images... Is there a way to get images to the center with some padding to them in Bootstrap? Below is my code:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
.row {
display: flex;
align-items: center;
justify-content: center;
}
.column {
flex: 33.33%;
padding: 50px;
width: 100%;
}
<div class="album text-center">
<div class="row">
<div class="column">
<img src="images/tour1.jpeg" alt="one" style="width:100%">
</div>
<div class="column">
<img src="images/tour2.jpg" alt="two" style="width:100%">
</div>
<div class="column">
<img src="images/tour3.jpeg" alt="three" style="width:100%">
</div>
<div class="column">
<img src="images/tour1.jpeg" alt="one" style="width:100%">
</div>
<div class="column">
<img src="images/tour2.jpg" alt="two" style="width:100%">
</div>
<div class="column">
<img src="images/tour3.jpeg" alt="three" style="width:100%">
</div>
</div>
</div>
Thank you!
Bootstrap 4 has justify-content-around class which does the job. Consider to use narrower container If you want to obtain smaller gap between images.
PS: You should avoid using col class within image wrappers.
<div class="container">
<div class="row justify-content-around">
<div class="colx"><img src="https://place-hold.it/200x400" alt="" class="img-fluid"></div>
<div class="colx"><img src="https://place-hold.it/200x400" alt="" class="img-fluid"></div>
<div class="colx"><img src="https://place-hold.it/200x400" alt="" class="img-fluid"></div>
</div>
</div>
JSFiddle
Just add this class "justify-content-around".
<div class="album">
<div class="row justify-content-around">
<div class="column">
<img src="images/tour1.jpeg" alt="one" style="width:100%">
</div>
<div class="column">
<img src="images/tour2.jpg" alt="two" style="width:100%">
</div>
<div class="column">
<img src="images/tour3.jpeg" alt="three" style="width:100%">
</div>
<div class="column">
<img src="images/tour1.jpeg" alt="one" style="width:100%">
</div>
<div class="column">
<img src="images/tour2.jpg" alt="two" style="width:100%">
</div>
<div class="column">
<img src="images/tour3.jpeg" alt="three" style="width:100%">
</div>
</div>
</div>
Example what i need:
Image:
My code is this:
<div class="container">
<div class="row">
<div class="col-3">
<img src="image1.png" class="img-thumbnail float-left" alt="Novi Sad">
</div>
<div class="col-6">
<img src="image1.png" class="img-thumbnail mx-auto d-block" alt="Belgrade">
</div>
<div class="col-3">
<img src="image1.png" class="img-thumbnail float-right" alt="Niš">
</div>
</div>
<!-- THIS IS PROBLEM -->
<div class="row">
<!-- THIS COLUMN NEED TO BE BELOW 1 COLUMN / LEFT SIDE -->
<div class="col-3">
<img src="image1.png" class="img-thumbnail float-left" alt="Novi Sad">
</div>
<!-- THIS COLUMN NEED TO BE BELOW 3 COLUMN / RIGHT SIDE -->
<div class="col-3 ml-auto">
<img src="image1.png" class="img-thumbnail float-right" alt="Novi Sad">
</div>
</div>
<!-- END PROBLEM -->
<div class="row">
<div class="col-4">
<img src="image1.png" class="img-thumbnail float-left" alt="Novi Sad">
</div>
<div class="col-4">
<img src="image1.png" class="img-thumbnail mx-auto d-block" alt="Novi Sad">
</div>
<div class="col-4">
<img src="image1.png" class="img-thumbnail float-right" alt="Novi Sad">
</div>
</div>
</div>
I can't figure where is the problem. If someone know where problem is, write solution. Thanks
PS. Sorry for my Bad english
Thanks All..
Edit: I've updated my answer to include background images, and to mimic the original layout better. Thanks to AndreiGheorghiu for help answering this more accurately.
.grid{
display: grid;
grid-gap:10px;
height:500px;
grid-template-columns: 1fr .2fr 1fr .2fr 1fr;
grid-template-areas: "topLeft large large large topRight"
"midLeft large large large midRight"
"bottomLeft bottomLeft bottomCenter bottomRight bottomRight";
}
.pic{
background: url(https://placeimg.com/400/400/any) no-repeat center/cover;
font: 700 20px sans-serif;
color:white;
display:flex;
align-items:center;
justify-content:center;
text-shadow:2px 2px 5px #000;
}
.pic-1{
grid-area: topLeft;
}
.pic-2{
grid-area: large;
}
.pic-3{
grid-area: topRight;
}
.pic-4{
grid-area: midLeft;
}
.pic-5{
grid-area: midRight;
}
.pic-6{
grid-area: bottomLeft;
}
.pic-7{
grid-area: bottomCenter;
}
.pic-8{
grid-area: bottomRight;
}
<div class="grid">
<div class="pic pic-1">Foxwoods</div>
<div class="pic pic-2">New York City</div>
<div class="pic pic-3">Las Vegas</div>
<div class="pic pic-4">Philadelphia</div>
<div class="pic pic-5">San Francisco</div>
<div class="pic pic-6">Miami</div>
<div class="pic pic-7">Boston</div>
<div class="pic pic-8">Washington D.C.</div>
</div>
You can try this code,
Note: Included responsive classes. Run this code as a full page
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col">
<img src="https://via.placeholder.com/800x800" class="img-fluid img-thumbnail" alt="Novi Sad">
<img src="https://via.placeholder.com/800x800" class="img-fluid img-thumbnail mt-md-4" alt="Novi Sad">
</div>
<div class="col-md-6">
<img src="https://via.placeholder.com/800x800" class="img-fluid img-thumbnail" alt="Belgrade">
</div>
<div class="col">
<img src="https://via.placeholder.com/800x800" class="img-fluid img-thumbnail" alt="Niš">
<img src="https://via.placeholder.com/800x800" class="img-fluid img-thumbnail mt-md-4" alt="Novi Sad">
</div>
</div>
<div class="row mt-md-4">
<div class="col-md-4">
<img src="https://via.placeholder.com/800x800" class="img-fluid img-thumbnail" alt="Novi Sad">
</div>
<div class="col-md-4">
<img src="https://via.placeholder.com/800x800" class="img-fluid img-thumbnail" alt="Novi Sad">
</div>
<div class="col-md-4">
<img src="https://via.placeholder.com/800x800" class="img-fluid img-thumbnail" alt="Novi Sad">
</div>
</div>
</div>
You need to put the small images in the same col. And display them as blocks: display:block; width: 100%; height: auto;.
Here's how I'd personally do it. I'm using .no-gutter class on .rows and white borders on images:
[my-gallery]:not(#_) {
padding: 8px;
}
[my-gallery] img {
display: block;
background-color: #f5f5f5;
width: 100%;
height: auto;
border: 8px solid white;
}
[my-gallery] .strethed img {
height: 100%;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid" my-gallery>
<div class="row no-gutters">
<div class="col">
<img src="https://picsum.photos/300/200/?random" alt="Novi Sad">
<img src="https://picsum.photos/303/202/?random" alt="Novi Sad">
</div>
<div class="col-6 strethed">
<img src="https://picsum.photos/306/204/?random" alt="Belgrade">
</div>
<div class="col">
<img src="https://picsum.photos/309/206/?random" alt="Niš">
<img src="https://picsum.photos/312/208/?random" alt="Novi Sad">
</div>
</div>
<div class="row no-gutters" >
<div class="col">
<img src="https://picsum.photos/315/210/?random" alt="Novi Sad">
</div>
<div class="col">
<img src="https://picsum.photos/318/212/?random" alt="Novi Sad">
</div>
<div class="col">
<img src="https://picsum.photos/321/214/?random" alt="Novi Sad">
</div>
</div>
</div>
i have problem in Bootstrap Thumbnails.
my thumbnails is like that:
img01. but want to be horizontal.
What am i doing ?
My Code:
HTML:
<div class="hrs" align="center">
<div class="row">
<div class="col-xs-6 col-lg-6 col-md-6 col-sm-6">
<div class="thumbnail">
<img src="img/AxMahsool.jpg" alt="AxMahsool01" class="img-responsive" />
<img src="img/AxMahsool.jpg" alt="AxMahsool02" class=" img-responsive" />
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-lg-6 col-md-6 col-sm-6">
<div class="thumbnail">
<img src="img/AxMahsool.jpg" alt="AxMahsool03" class=" img-responsive" />
<img src="img/AxMahsool.jpg" alt="AxMahsool04" class=" img-responsive" />
</div>
</div>
</div>
</div>
Css:
.hrs{
display: table;
margin: 0 auto;
padding: 20px;
color: white;
It's because you have them in separate <div class="row"> containers. What you should do is put all of your images in the same row container(so take out the second <div class="row">) -and/or- try adding this code to your CSS:
.thumbnail>img { display: inline-block; }
So I have basically used manual percentages to make these images lie next together. As you see they are not very neatly layout or organized. How can I make it look more dashing?
Here's the code:
<div class="jumbotron jumbotron-fluid" style=" margin-top: 90px; ">
<div class="container">
<div class="row">
<div class="col-lg-2">
<img src="./assets/img/glass.jpg" class="img-responsive " style="width:95%"/>
<img src="./assets/img/rift.jpg" class="img-responsive m-y-1" style="width:95%;"/>
</div>
<div class="col-lg-8">
<img src="./assets/img/mhacks.jpg" class="img-responsive" style="width:100%; "/>
</div>
<div class="col-lg-2">
<img src="./assets/img/mindwave.png" class="img-responsive" style="width:120%;"/>
<img src="./assets/img/VR.png" class="img-responsive m-y-1" style="width:120%;"/>
</div>
</div>
</div>
</div>
Here's how it looks like:
http://imgur.com/e2I3yLu
Also here's the link to the website:
monajalal.github.io
Any suggestion is really appreciated. I wonder if there's a more straightforward method to image layout or any automatic method?
Set each image as a background image in a div:
<div class="jumbotron jumbotron-fluid" style=" margin-top: 90px; ">
<div class="container">
<div class="row">
<div class="col-lg-2">
<div style="background: url('./assets/img/glass.jpg'); background-size: cover;" class="img-responsive"></div>
<div style="background: url('./assets/img/rift.jpg'); background-size: cover;" class="img-responsive"></div>
</div>
<div class="col-lg-8">
<div style="background: url('./assets/img/mhacks.jpg'); background-size: cover;" class="img-responsive-large"></div>
</div>
<div class="col-lg-2">
<div style="background: url('./assets/img/mindwave.png'); background-size: cover;" class="img-responsive"></div>
<div style="background: url('./assets/img/VR.png'); background-size: cover;" class="img-responsive"></div>
</div>
</div>
</div>
</div>
Then set this css:
.img-responsive {padding-top: 60%; margin-bottom: 10px;}
.img-responsive-large {height: 208px; margin-bottom: 10px;}
#media screen and (max-width: 940px) {
.img-responsive-large {height: auto; padding-top: 60%;}
}
Try this... What I did was work with the grid. Use the padding from columns and even it with margins between the images, also set the images to 100% width. Class img-responsive sets a max-width of 100%, at least this way the image will fill the column.
<div class="jumbotron jumbotron-fluid">
<div class="container">
<div class="row">
<div class="col-lg-8">
<img src="http://www.online-image-editor.com//styles/2014/images/example_image.png" class="img-responsive"/>
</div>
<div class="col-lg-2">
<img src="http://www.online-image-editor.com//styles/2014/images/example_image.png" class="img-responsive "/>
<img src="http://www.online-image-editor.com//styles/2014/images/example_image.png" class="img-responsive m-y-1"/>
</div>
<div class="col-lg-2">
<img src="http://www.online-image-editor.com//styles/2014/images/example_image.png" class="img-responsive"/>
<img src="http://www.online-image-editor.com//styles/2014/images/example_image.png" class="img-responsive m-y-1"/>
</div>
</div>
</div>
</div>
Remove the inline styling - and instead target the images in the css and add this.
.jumbotron img { width: 100%; margin: 15px 0; }