how do i create a photo collage with html css and bootstrap - html

I tried adding images to the div it did't work for me,
<img
class="img-fluid"
src="https://via.placeholder.com/800x800"
style="border-radius: 20px"
/>
Therefore I tried adding background images to divs, and when i add images to the divs the images wont show?can anyone tell me a solution to this and why this is hapenning?
<div class="col-lg-6">
<!-- ??????? how do i create the grid -->
<div class="row g-0">
<div class="col-lg-4">
<div
class="imgcollage"
style="background-image: url(../img/img2.jpg)"
></div>
</div>
<div class="col-lg-8">
<div
class="imgcollage"
style="background-image: url(../img/img2.jpg)"
></div>
</div>
</div>
<div class="row g-0">
<div class="col-lg-8">
<div
class="imgcollage"
style="background-image: url(../img/img2.jpg)"
></div>
</div>
<div class="col-lg-4">
<div
class="imgcollage"
style="background-image: url(../img/img3.jpg)"
></div>
</div>
</div>
</div>
here's the css
.imgcollage {
height: 100%;
width: 100%;
background-position: center;
background-size: cover;
border-radius: 20px;
}

sorry i'm posting another answer with working pictures the other pics didn't work because they aren't actually urls
.imgcollage {
height: 100%;
width: 100%;
background-position: center;
background-size: cover;
border-radius: 20px;
}
.col-lg-6{
display:grid;
/* declares how many columns there will automaticaly be and how big they will be +rows and how big of a gap between them*/
grid-template-columns: 250px 250px;
grid-template-rows: 250px 250px;
grid-gap: 15px;
<div class="col-lg-6">
<!-- ??????? how do i create the grid -->
<div
class="imgcollage"
style="background-image: url(https://images.pexels.com/photos/2253275/pexels-photo-2253275.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500)"
></div>
<div
class="imgcollage"
style="background-image: url(https://images.pexels.com/photos/1108099/pexels-photo-1108099.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500)"
></div>
<div
class="imgcollage"
style="background-image: url(https://images.pexels.com/photos/731022/pexels-photo-731022.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500)"
></div>
<div
class="imgcollage"
style="background-image: url(https://images.pexels.com/photos/2623968/pexels-photo-2623968.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500)"
></div>
</div>

Related

Set DIV to size of background-image

So I am trying to figure out, how I can set the size of the second Box (see screenshot) to the size of the background image. I am using bootstrap and it's build flex classes. Maybe you guys can help me out here.
Essentially what I would like to have is the purple box to be the same size of the background image and keep being the same size on resizing the screen.
To test things out, I provided a prepared Stackblitz environment: https://stackblitz.com/edit/javascript-rs3ykl?file=index.html
.page-container {
width: 100vw;
height: 50vh;
}
.background-image {
background: url('https://dummyimage.com/258x362/007aa5?text=Banner-Desktop-Large') center center / contain no-repeat;
height: 100%;
width: auto;
background-origin: content-box;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="page-container">
<div class="row w-100 h-100">
<div class="col-4 bg-primary">
<p>Box 1</p>
</div>
<div class="col-4">
<div class="background-image">
<div style="background: purple">
<div class="d-flex justify-content-around" style="color: rgb(255, 255, 255)">
<div class="d-flex flex-column">
<div>Tage</div>
<div>16086</div>
</div>
<div class="d-flex flex-column">
<div>Stunden</div>
<div class="">6</div>
</div>
<div class="d-flex flex-column">
<div>Minuten</div>
<div>13</div>
</div>
<div class="d-flex flex-column">
<div>Sekunden</div>
<div>34</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-4 bg-secondary">
<p>Box 3</p>
</div>
</div>
</div>
I think it's better to use image tag instead of url with div. so I changed it like this
<link
href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous"
/>
<style>
.page-container {
width: 100vw;
height: 50vh;
}
.background-image {
height: 100%;
width: auto;
background-origin: content-box;
}
.bk-image {
object-fit: cover;
width: 100%;
height: 100%;
}
</style>
<div class="page-container">
<div class="row w-100 h-100">
<div class="col-4 bg-primary"><p>Box 1</p></div>
<div class="col-4">
<div class="background-image">
<div style="background: purple">
<div class="d-flex justify-content-around" style="color: rgb(255, 255, 255)">
<div class="d-flex flex-column">
<div>Tage</div>
<div>16086</div>
</div>
<div class="d-flex flex-column">
<div>Stunden</div>
<div class="">6</div>
</div>
<div class="d-flex flex-column">
<div>Minuten</div>
<div>13</div>
</div>
<div class="d-flex flex-column">
<div>Sekunden</div>
<div>34</div>
</div>
</div>
</div>
<img class="bk-image" src = "https://dummyimage.com/258x362/007aa5?text=Banner-Desktop-Large">
</div>
</div>
<div class="col-4 bg-secondary"><p>Box 3</p></div>
</div>
</div>
and now the purple bar stays with the background picture, also since you used height 100% I did it too but if you want it to stay inline with the row you can set the height as the same as row height.

bootstrap 4 - arrange images in particular?

I created a simple page in my Laravel and in that page, I have three sections which is mainly navigation, content and footer. I got the navigation and footer layout completed. In the content section, I wish to use bootstrap to place my images layout like this:
Image:
This is just a general idea but I need it to be responsive so it fits the mobile layout as well.
What I have tried is to use Masonry for CSS but it does not fit the mobile layout responsively. I tried using bootstrap 4 but the alignment between IMG3 and IMG4/5 are too far apart and placing margin does not align them near enough.
My code:
#section('content')
<div class="container">
<div class="row">
<div class="col-sm">
<img src="{{asset('/images/Home_Bed.jpg')}}" class="img-fluid custom-position-1" alt="">
</div>
<div class="col-sm col-8">
<img src="//via.placeholder.com/350x150" class="img-fluid custom-position-2" alt="">
</div>
<div class="col-sm custom-position-3">
<img src="{{asset('/images/Home_Kitchen.jpg')}}" class="img-fluid custom-position-3" alt="">
</div>
</div>
<div class="row align-items-end">
<div class="col col-8">
<img src="{{asset('/images/Shop_Page.jpg')}}" class=" img-fluid custom-position-4" alt="">
</div>
<div class="col">
<img src="{{asset('/images/Home_Sofa.jpg')}}" class="img-fluid custom-position-5" alt="">
</div>
</div>
</div>
#endsection
.row {
margin-bottom: 30px;
}
.custom-position-1{
position: relative;
bottom: -160px;
left: 50px;
height:100px;
object-fit: cover;
}
.custom-position-2{
position:relative;
right:100px;
object-fit:cover;
}
.custom-position-3{
position: relative;
bottom: -160px;
left: 50px;
height:100px;
object-fit: cover;
}
.custom-position-4{
position: relative;
height: 400px;
width:800px;
object-fit: cover;
}
.custom-position-5{
position: relative;
height:300px;
left:50px;
top: 100px;
object-fit: cover;
}
Does anyone have any idea how to make it good?
Are you looking for a solution like this?
If you want to have some spacing use margin classes.
img {
width: 100%;
height: 100%;
}
[class*="col-"],
.flex-grow-0 {
border: 1px solid black;
}
.img-fluid {
padding: 5px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<div class="container">
<div class="row m-0">
<div class="col-8 p-0">
<div class="row m-0">
<div class="col-6 p-0">
<img src="http://placehold.it/300x300" class="img-fluid" alt="" />
</div>
<div class="col-6 p-0">
<img src="http://placehold.it/300x300" class="img-fluid" alt="" />
</div>
<div class="col-12 p-0">
<img src="http://placehold.it/300x300" class="img-fluid" alt="" />
</div>
</div>
</div>
<div class="col-4 p-0 d-flex">
<div class="d-flex flex-column">
<div class="flex-grow-0 mt-auto">
<img src="http://placehold.it/300x500" class="img-fluid" alt="" />
</div>
<div class="flex-grow-0">
<img src="http://placehold.it/400x400" class="img-fluid" alt="" />
</div>
</div>
</div>
</div>
</div>

Bootstrap images in columns overlapping

I have been trying to get 3 images to be responsive using bootstrap columns. They seem to be responsive, but the problem is that the images overlap except for the last column which remains being normal.
<div class="row">
<div class="col-sm-2 offset-sm-3">
<img class="img-responsive" src="../assets/images/roy-creates-categories-02.png">
</div>
<div class="col-sm-2">
<img class="img-responsive" src="../assets/images/roy-creates-categories-02.png">
</div>
<div class="col-sm-2">
<img class="img-responsive" src="../assets/images/roy-creates-categories-02.png">
</div>
</div>
I would like all 3 columns to like the one all the way on the right.
I've tried adding class "img-responsive" & "img-fluid" and neither have worked.
I'm using bootstrap 4.0.
The images are overflowing their container. The image on the right is full height but it is overflowing its container. Using the bootstrap '.col-2' means that you are limiting the column widths based on the window width. You could use background css rules instead of img elements to ensure containment or coverage of images or you could just use .col-auto instead of .col-2 with .justify-content-center provided you have appropriately sized images.
All three examples are in the snippet.
.row {
min-height: 150px;
}
.col-auto {
background-color: green;
}
.col-sm-2 {
background-color: red;
}
.bg-image {
width: 100%;
height: 100%;
background-image: url("https://picsum.photos/100");
background-position: center;
background-size: contain;
background-repeat: no-repeat;
}
.bg-image.bg-image--cover {
background-size: cover;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="row justify-content-center">
<div class="col-auto">
<img class="img-fluid" src="https://picsum.photos/100">
</div>
<div class="col-auto">
<img class="img-fluid" src="https://picsum.photos/100">
</div>
<div class="col-auto">
<img class="img-fluid" src="https://picsum.photos/100">
</div>
</div>
<div class="row">
<div class="col-sm-2 offset-sm-3">
<div class="bg-image"></div>
</div>
<div class="col-sm-2">
<div class="bg-image"></div>
</div>
<div class="col-sm-2">
<div class="bg-image"></div>
</div>
</div>
<div class="row">
<div class="col-sm-2 offset-sm-3">
<div class="bg-image bg-image--cover"></div>
</div>
<div class="col-sm-2">
<div class="bg-image bg-image--cover"></div>
</div>
<div class="col-sm-2">
<div class="bg-image bg-image--cover"></div>
</div>
</div>

Make the image layout more organized using bootstrap and CSS

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; }

What would cause bootstrap columns to act like rows?

I cannot figure out why these column classes are not acting properly. They are vertically stacking. I am fairly new to boostrap, so I could be missing something obvious.
Any help would be appreciated. Thanks ahead of time.
HTML-
<div class="row content-container">
<div class="row top-nav">
<div class="row header">
<div class="col-lg-4 logo">
<img src="images/logo.png">
</div>
<div class="col-lg-8 nav-area">
<div class="row number">
888.888.8888
</div>
<div class="row navigation">
</div>
<div class="row heading">
</div>
</div>
</div>
<div class="row sub-nav">
</div>
</div>
<div class="row content-footer"></div>
</div>
SCSS-
.content-container{
position: relative;
background-image:url("images/border-vertical.png"), url("images/parchment-bg.jpg"), url("images/border-vertical.png");
background-position: top left, top center, top right;
background-origin: border-box, content-box, border-box;
background-repeat: repeat-y, repeat-y, repeat-y;
height: 1500px;
width: 972px;
margin: auto;
padding: 20px 56px 0 56px;
.nav-area{
position: relative;
.number{
background-image:url("images/phone-number-bg.png")
}
}
.content-footer{
background-image: url("images/border-horizontal.png");
background-repeat: repeat-x;
background-origin:content-box;
height: 31px;
width: 892px;
position: absolute;
bottom: 0px;
left: 40px;
}
}
First off, you don't need to put the class row in every div that contained your col-lg-*
But you can still stack them however you want though.
Example :
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-4">
...
</div>
</div>
</div>
</div>
As for your problem, you were right about the columns breaking up when you reach the min-width of col-lg-*. This is a feature of bootstrap. This prevents your columns shrinking so much that it becomes unreadable.
You could however, add the grid classes for smaller views. Like this:
<div class="row header">
<div class="col-md-4 col-lg-4 logo">
<img src="images/logo.png">
</div>
<div class="col-md-8 col-lg-8 nav-area">
<div class="row number">
888.888.8888
</div>
<div class="row navigation">
</div>
<div class="row heading">
</div>
</div>
</div>