How to make a responsive stack of images within bootstrap grids - html

I'm creating a small website as a home project to show off my artworks. At the main page I want to show recently updated collections with the latest works stacked like a stack of cards with a small offset. Each stack gets its own grid column.
This is what I have so far: http://www.bootply.com/Dus21AApn5
<div class="container-flow">
<h2> Recent Collection Updates</h2>
<div class="row" style="margin: 0.05%;">
<div class="col-sm-4 col-xs-6">
<div style="position: absolute;
max-height: 200px;
margin: auto;
overflow: hidden;
top: 0px;
left: 0px;
z-index: -0;
-webkit-box-shadow: 2px 2px 1px 3px rgba(0,0,0,0.2);
-moz-box-shadow: 2px 2px 1px 3px rgba(0,0,0,0.2);
box-shadow: 2px 2px 1px 3px rgba(0,0,0,0.2);">
<img style="max-width: 200px;" class="img-responsive" src="http://placehold.it/250x350">
</div>
...
</div>
<div class="col-sm-4 col-xs-6"> ... </div>
<div class="col-sm-4 col-xs-6"> ... </div>
</div>
</div>
The code is a bit messy because it's generated by a template engine (I'll move all the styles to CSS-files later).
I got it to work so it looks like the images are stacked on each other but unfortunately at the same time it broke the responsiveness of the bootstrap grid. The grid columns don't stack anymore and just merge into each other. I figured out it's due to the position of the div, which contains the images, being set to absolute. I can't find a way to keep my image stack and at the same time the responsiveness.
I searched the internet for a while but didn't find a solution. Since I'm not a Web-(Front-End)-Developer I have very little experience with HTML/CSS and the like.
If someone could give me a solution or point me in the right direction so I can fix it myself, that would be nice.
I'd like to avoid additional JavaScript wherever possible.

Here is a solution, but due to all divs inside bootstrap grid cell (col-*...) are absolutely positioned, they forced to get their height by jquery script to avoid overlapping.
.imageBanner {
display: block;
position: relative;
margin: 0 auto;
padding: 0;
width: 100%;
height: 40vw;
}
#media screen and (max-width: 767px) {
.imgBanner {
height: 30vw;
}
}
.image1 {
left: 0;
top: 0;
z-index: -1;
}
.image2 {
top: 0;
left: 10%;
z-index: -2;
}
.image3 {
top: 0;
left: 20%;
z-index: -3;
}
.imageBanner div {
width: 75%;
max-height: 85%;
display: block;
position: absolute;
overflow: hidden;
-webkit-box-shadow: 2px 2px 1px 3px rgba(0,0,0,0.2);
-moz-box-shadow: 2px 2px 1px 3px rgba(0,0,0,0.2);
box-shadow: 2px 2px 1px 3px rgba(0,0,0,0.2);
}
.imageBanner div img {
width: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-flow">
<h2 class=""> Recent Collection Updates</h2>
<div class="row" style="margin: 0.05%;">
<div class="col-sm-4 col-xs-6">
<div class="imageBanner">
<div class="image1">
<img src="https://unsplash.it/600/400/" class="img-responsive">
</div>
<div class="image2">
<img src="https://unsplash.it/400/600/" class="img-responsive">
</div>
<div class="image3">
<img src="https://unsplash.it/500/500/" class="img-responsive">
</div>
</div>
</div>
<div class="col-sm-4 col-xs-6">
<div class="imageBanner">
<div class="image1">
<img src="https://unsplash.it/800/600/" class="img-responsive">
</div>
<div class="image2">
<img src="https://unsplash.it/200/200/" class="img-responsive">
</div>
<div class="image3">
<img src="https://unsplash.it/600/800/" class="img-responsive">
</div>
</div>
</div>
<div class="clearfix visible-xs-block"></div>
<div class="col-sm-4 col-xs-6">
<div class="imageBanner">
<div class="image1">
<img src="https://unsplash.it/300/400/" class="">
</div>
<div class="image2">
<img src="https://unsplash.it/600/600/" class="">
</div>
<div class="image3">
<img src="https://unsplash.it/400/200/" class="">
</div>
</div>
</div>
</div>
</div>
Also you can view another variant of images interposition here: https://stackoverflow.com/a/41048391/4206079

Related

Align content in div: absolute to bottom AND relative to center

I have been trying to align content in a div to the bottom (which seems only to work with absolute) AND at the same time to position the content in the center.
In my code below, the problem refers to the images, which are either centered and at top OR left and bottom, but never both.
I have tried different CSS approaches as well as just using an old fashioned table for around the image, but nothing seems to work to get both at the same time.
How to position the images center and at bottom?
jsfiddle
.x-offer:nth-of-type(1) {
background-color: #c5d7d9;
}
.x-offer:nth-of-type(2) {
background-color: #e6e0cf;
}
.x-offer:nth-of-type(3) {
background-color: #debfb5;
}
.x-offer {
padding: 20px 0 0 0 !important;
}
.x-offer.nails > .flex-column {
width: 90%;
}
.x-offer > .flex-column {
width: 100%;
}
.x-offer > .flex-column > div:nth-of-type(2) {
bottom: 0px;
width: 75%;
margin: 0px auto;
position: absolute;
bottom: 0;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.14.0/css/all.css" integrity="sha384-HzLeBuhoNPvSl5KYnjx0BT+WB0QEEqLprO+NBkkk5gbc67FTaL7XIGa2w1L0Xbgc" crossorigin="anonymous">
<div class="container">
<div class="row" style="height: 250px;">
<!-- STYLING -->
<div class="col-sm text-center d-flex align-items-top justify-content-center x-offer styling">
<div class="flex-column justify-content-center" style="border: 1px solid green;">
<div style="border: 1px solid;">
STYLING<p> </p>
</div>
<div style="border: 1px solid;">
<img src="http://davids134.sg-host.com/wp-content/uploads/2020/08/service1.gif" style="max-height: 50%; max-width: 100%">
</div>
</div>
</div>
<!-- HAIR -->
<div class="col-sm text-center d-flex align-items-top justify-content-center x-offer hair">
<div class="flex-column" style="border: 1px solid green;">
<div style="border: 1px solid;">
HAIR<p> </p>
</div>
<div style="border: 1px solid;">
<img src="http://davids134.sg-host.com/wp-content/uploads/2020/08/service3.gif" style="max-height: 50%; max-width: 100%">
</div>
</div>
</div>
<!-- NAILS -->
<div class="col-sm text-center d-flex align-items-top justify-content-center x-offer nails ">
<div class="flex-column" style="border: 1px solid green;">
<div style="border: 1px solid;">
NAILS<p> </p>
</div>
<div style="border: 1px solid;">
<img src="http://davids134.sg-host.com/wp-content/uploads/2020/08/service2.gif" style="max-height: 50%; max-width: 100%">
</div>
</div>
</div>
</div> </div>
Modify style of your .x-offer > .flex-column > div:nth-of-type(2)
Add left and right parameters, and set them to 0:
.x-offer > .flex-column > div:nth-of-type(2) {
bottom: 0px;
width: 75%;
margin: 0px auto;
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
Here's fiddle
You should add the classes d-flex and align-items-center to the divs that currently have the flex-column class applied:
<div class="d-flex align-items-center flex-column" style="border: 1px solid green;">
You can see more about flex in bootstrap 4 documentation here: https://getbootstrap.com/docs/4.0/utilities/flex/
There are 2 things you need (I mark them in code).
A flex container
An item, which expands within this container (to push last element down)
.x-offer {
border: 1px solid green;
height: 250px;
}
.image-bottom-wrapper {
text-align: center;
}
.image-bottom-wrapper img {
max-width: 100px;
max-height: 50px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" />
<div class="container">
<div class="row">
<div class="col col-4 x-offer styling d-flex flex-column"><!-- [1] -->
<div class="headline">
STYLING
</div>
<div class="flex-grow-1 text"><!-- [2] -->
Some Text Here...
</div>
<div class="image-bottom-wrapper">
<img src="https://dummyimage.com/300x200/CCC/000" />
</div>
</div>
</div>
</div>

Image not being responsive. I have tried both adding img-responsive class and setting height to auto in css

This is my html code.
<div class="column">
<div class="slider" id="main-slider">
<div class="slider-wrapper">
<img src="images/11.jpg" class="slide img-responsive">
</div>
</div>
</div>
This is the css part.
img{
border-color: white; border-radius: 8px;border: 1px solid #ddd;
max-width: 100%;
float: left;
margin: 0 5% 80px 0;
width:100%;
height:auto;
}
The image not being responsive. I have tried both adding img-responsive class and setting height to auto in css. It does not shrink when I reduce the browser size.
Bootstrap 4 use img-fluid instead of img-responsive. Read its documentation here
Try to replace this code
img {
border-color: white;
border-radius: 8px;
border: 1px solid #ddd;
max-width: 100%;
margin: 0 5% 80px 0;
height: auto;
}
I have put your code into JSFiddle with an image without the img-responsive class and everything seems to be working fine?
<div class="column">
<div class="slider" id="main-slider">
<div class="slider-wrapper">
<img src="https://www.gettyimages.co.uk/gi-resources/images/Embed/new/embed2.jpg">
</div>
</div>
</div>
https://jsfiddle.net/zhg95pa8/
Delete the class and see if that works any better.
Add width="100%" to <img> tag and remove width from img css part. That's it :)
img{
border-color: white; border-radius: 8px;border: 1px solid #ddd;
max-width: 100%;
float: left;
margin: 0 5% 80px 0;
/*width:100%;*/
/*height:auto;*/
}
<div class="column">
<div class="slider" id="main-slider">
<div class="slider-wrapper">
<img src="https://cdn.dribbble.com/users/1928643/screenshots/4451111/shot3.jpg" class="slide img-responsive" width="100%">
</div>
</div>
</div>

Two definition of the same item in the same div class

I need to use an item, in this case img, in the same div class but with different definitions.
Example:
section .row img {
margin: 0 0 30px;
width: 100%;
border: 4px solid #18a00e;
}
section .row img {
margin: 0 0 30px;
border: 4px solid #18a00e;
max-height: 300px;
}
How can I create and use this two definitions without the last one overwriting the former?
Thank you.
Later edit (for more info):
//this is the html code scenario 1 where I need the width: 100%//
<section class="container">
<div class="row">
<figure class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
<img src="img/m3.jpg"/>
</figure>
</div>
</section>
//this is the html code for scenario 2, where I need max-height: 300px//
<section class="jumbotron">
<div class="unlockedl">
<div class="row">
<img src="img/pm1.jpg"/>
</div>
</div>
</section>
You have classes that you can use to uniquely target those elements. use .container and .jumbotron to target the .row img in those individual sections instead of the generic section element.
.container .row img {
margin: 0 0 30px;
width: 100%;
border: 4px solid #18a00e;
}
.jumbotron .row img {
margin: 0 0 30px;
border: 4px solid #18a00e;
max-height: 300px;
}
<section class="container">
<div class="row">
<figure class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
<img src="img/m3.jpg" />
</figure>
</div>
</section>
<section class="jumbotron">
<div class="unlockedl">
<div class="row">
<img src="img/pm1.jpg" />
</div>
</div>
</section>
You can also use other unique classes/elements in those 2 blocks, like figure and .unlockedl
section figure img {
margin: 0 0 30px;
width: 100%;
border: 4px solid #18a00e;
}
section .unlockedl img {
margin: 0 0 30px;
border: 4px solid #18a00e;
max-height: 300px;
}
<section class="container">
<div class="row">
<figure class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
<img src="img/m3.jpg" />
</figure>
</div>
</section>
<section class="jumbotron">
<div class="unlockedl">
<div class="row">
<img src="img/pm1.jpg" />
</div>
</div>
</section>
Or you can use :nth-child() to target individual sections
section:nth-child(1) .row img {
margin: 0 0 30px;
width: 100%;
border: 4px solid #18a00e;
}
section:nth-child(2) .row img {
margin: 0 0 30px;
border: 4px solid #18a00e;
max-height: 300px;
}
<section class="container">
<div class="row">
<figure class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
<img src="img/m3.jpg" />
</figure>
</div>
</section>
<section class="jumbotron">
<div class="unlockedl">
<div class="row">
<img src="img/pm1.jpg" />
</div>
</div>
</section>
You should assign an unique id and assign the css to the distinct id
<div id ='id1' class='same_class'> </div>
<div id='id2' class='same_class'> </div>
#id1 {
width: 100%;
}
#id2 {
max-height: 300px;
}
.same_class{
margin: 0 0 30px;
border: 4px solid #18a00e;
}

How to get better control over responsive images break point and alignment with BS3

I am trying to control some responsive images placed in a grid.
Unfortunately 2 annoying things occur when the viewport is changed in width:
The images which starts out as 4 in a row, quickly becomes 1 in a row even though there is space enough for 2-3 in the viewport.
The images are not positioned in center when 1 in a row.
HTML
<section>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 text-center">
<h2>Image test</h2>
<hr class="line-color"></hr>
</div>
</div>
<div class="row team-images">
<div class="col-md-3">
<div class="team-item">
<div class="team-text">
<h3>John Doe</h3>
<h4>COO</h4>
</div>
<div class="team-image-overlay"></div>
<img src="http://placehold.it/400x400" class="img-responsive" alt="" />
</div>
</div>
<div class="col-md-3">
<div class="team-item">
<div class="team-text">
<h3>Moe Joe</h3>
<h4>COO</h4>
</div>
<div class="team-image-overlay"></div>
<img src="http://placehold.it/400x400" class="img-responsive" alt="" />
</div>
</div>
<div class="col-md-3">
<div class="team-item">
<div class="team-text">
<h3>Jimbo Joe</h3>
<h4>COO</h4>
</div>
<div class="team-image-overlay"></div>
<img src="http://placehold.it/400x400" class="img-responsive" alt="" />
</div>
</div>
<div class="col-md-3">
<div class="team-item">
<div class="team-text">
<h3>Jimmy Joe</h3>
<h4>COO</h4>
</div>
<div class="team-image-overlay"></div>
<img src="http://placehold.it/400x400" class="img-responsive" alt="" />
</div>
</div>
</div>
</div>
</section>
CSS
body {
margin: 10px;
}
.team-images img {
max-height:300px;
width:auto;
}
.team-text {
position: absolute;
width: 100%;
bottom: 0;
text-align: center;
background-color:rgba(0, 0, 0, 0.4);
}
.team-text h3 {
margin-top:5px;
font-weight: 300;
margin-bottom: 0;
text-transform: none;
}
.team-text h4 {
margin-bottom:5px;
margin-top: 0;
padding-top: 0;
font-weight: 200;
font-size: 1em;
text-transform: none;
}
.team-item {
position: relative;
display:inline-block;
margin-bottom:10px;
}
.team-images .team-image-overlay {
position: absolute;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(41, 128, 185, 0.4);
color: #fff;
-webkit-transition: all ease .5s;
-moz-transition: all ease .5s;
transition: all ease .5s;
}
.team-images .team-image-overlay:hover {
background: rgba(24, 188, 156, 0);
}
DEMO: https://jsfiddle.net/DTcHh/7189/
On your columns, you only specified col-md-3 which will only trigger during medium to large resolutions.
You can set instead col-md-3 col-sm-3 or just col-sm-3 so it will also trigger on smaller res.
Regarding the images not positioned center, you can make it by setting text-align:center on their container.
.team-images > div {
text-align:center;
}
Working fiddle : https://jsfiddle.net/1L4fgdf5/3/
In response to your comment below, if you don't want to use scaffolding use media queries on css intead.
#media (min-width: 992px) and (max-width: 1199px) {
.team-images .col-md-3 {
width: 50%;
}
}
Working fiddle: https://jsfiddle.net/da9b30fn/

Displaying Image caption with only HTML and CSS

I am trying to display caption on images.
This is my HTML
<div class="image-hover">
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
</div>
This is my CSS :
.image-hover {
overflow: hidden;
}
.image-hover .image-block {
width: 234px;
height: 100px;
display: inline-block;
border: 1px solid #666666;
}
.image-hover .image-block img {
width: 230px;
height: 100px;
border: 2px solid #fff;
}
.details, .image-backdrop {
float: left;
}
.details h4:after {
display: inline-block;
content:" ";
width: 0;
height: 0;
border-top: 6px solid transparent;
border-bottom: 6px solid transparent;
border-left: 8px solid #666666;
margin: 0 10px;
}
This is my JsFiddel
My problem is how can I get image's caption to above of image?
Any comments are greatly welcome.
Thank you.
you should use position:relative; to the container and position:absolute; to the child container whom you want to on image it is styled as you want
http://jsfiddle.net/ADMvd/2/
Add this to your CSS
.details h4 {
color: white; /* just to make it look pretty */
}
.details {
position: absolute;
}
.image-overlay {
position: relative;
}
DEMO
EDIT
Note that you are using div tag inside your a tag so don't forget to add display: block to your a.image-overlay tag because inline elements can't contain any other type of elements. It does work but will cause many weird problems.
For starters height:100% won't work for div inside a