CSS3 transform rotate images in flex layout with equal gutters - css

I'm trying to rotate images by 30 degrees and maintain equal margins between.
The desired result looks like a brick layout:
I am starting out with a wrapped flex layout:
And adding a 30deg rotation:
But notice the unevenness.
Here's the CSS:
.img-container {
display: flex;
flex-wrap: wrap;
justify-content: center;
.img-item {
flex: 0 0 50%;
#media #{$tablet} { & { flex: 0 0 25%; } }
#media #{$desktop} { & { flex: 0 0 20%; } }
/** padding for the gutters when using flexbox **/
padding: 5px 10px;
/** Transformation here
-webkit-transform: rotate(-30deg);
transform: rotate(-30deg);
/* chop off according to media queries - based off of 15 results*/
&:last-child {
display: none;
}
&:nth-last-child(-n+3) {
#media #{$tablet} { & { display: none; } }
#media #{$desktop} { & { display: initial; } }
}
.img {
object-fit: contain;
max-width: 100%;
}
}
}
HTML
<div class="img-container">
<div class="img-item">
<img class="img" src="http://www.logos.com/media/pbb/SampleCover.jpg" />
<img class="img" src="http://www.logos.com/media/pbb/SampleCover.jpg" />
<img class="img" src="http://www.logos.com/media/pbb/SampleCover.jpg" />
<img class="img" src="http://www.logos.com/media/pbb/SampleCover.jpg" />
<img class="img" src="http://www.logos.com/media/pbb/SampleCover.jpg" />
<img class="img" src="http://www.logos.com/media/pbb/SampleCover.jpg" />
<img class="img" src="http://www.logos.com/media/pbb/SampleCover.jpg" />
<img class="img" src="http://www.logos.com/media/pbb/SampleCover.jpg" />
<img class="img" src="http://www.logos.com/media/pbb/SampleCover.jpg" />
<img class="img" src="http://www.logos.com/media/pbb/SampleCover.jpg" />
<img class="img" src="http://www.logos.com/media/pbb/SampleCover.jpg" />
<img class="img" src="http://www.logos.com/media/pbb/SampleCover.jpg" />
<img class="img" src="http://www.logos.com/media/pbb/SampleCover.jpg" />
<img class="img" src="http://www.logos.com/media/pbb/SampleCover.jpg" />
<img class="img" src="http://www.logos.com/media/pbb/SampleCover.jpg" />
</div>
</div>=
I tried using CSS grids too, but had similar lack of interlocking brick layout and same vertical gutters and lack of horizontal gutters.

Related

Overlap Multiple Images In A Row

I know there are several threads on the "overlapping images" topic, but I can't find one that addresses my specific problem.
I have five circular images and I need to display them with slight overlap, kind of like how a deck of cards looks when it's laid out in a fan.
Here is what it should look like:
Here is what I currently have:
All the code examples I've found are aimed at overlapping two square images and I can't figure out how to translate to this scenario. Any help would be greatly appreciated.
I've tried messing around with grid layout and negative margins, but it was just a huge mess.
I can't share the source code but I've recreated the exact same HTML/CSS with dummy data in this codepen.
Code:
.main-container {
height: fit-content;
padding-top: 3rem;
}
#icons-container {
display: flex;
position: relative;
justify-content: center;
}
.icon {
height: 40px;
width: 40px;
border-radius: 50%;
border: 1px solid white;
}
<div class="main-container">
<div id="icons-container">
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon1" />
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon2" />
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon3" />
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon4" />
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon5" />
</div>
</div>
</div>
You can use margin-right/margin-left on the icon . To overlap, let margin-right have negative values
.main-container {
height: fit-content;
padding-top: 3rem;
}
#icons-container {
display: flex;
position: relative;
justify-content: center;
}
.icon {
height: 40px;
width: 40px;
border-radius: 50%;
border: 1px solid white;
margin-right: -15px;
}
<div class="main-container">
<div id="icons-container">
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon1">
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon2">
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon3">
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon4">
</div>
<div class="single-icon-container">
<img src="https://randomwordgenerator.com/img/picture-generator/50e4d646434faa0df7c5d57bc32f3e7b1d3ac3e45551784c722f78d79e_640.jpg" alt="" class="icon" id="icon5">
</div>
</div>
</div>

how to set width for item inside flex overflown [duplicate]

This question already has an answer here:
Why is a flex item limited to parent size?
(1 answer)
Closed 3 years ago.
I got code like this
.divA {
background: red;
width: 500px;
display: flex;
flex-direction: row;
overflow-y: scroll;
}
.epi {
width: 50%;
background: blue;
}
<div class="divA">
<div class="epi">
<h1>dsds</h1>
<p>sdsds</p>
<img src="img/heart.png" alt="" />
</div>
<div class="epi">
<h1>dsds</h1>
<p>sdsds</p>
<img src="img/heart.png" alt="" />
</div>
<div class="epi">
<h1>dsds</h1>
<p>sdsds</p>
<img src="img/heart.png" alt="" />
</div>
<div class="epi">
<h1>dsds</h1>
<p>sdsds</p>
<img src="img/heart.png" alt="" />
</div>
</div>
I'm expecting this
But I'm getting this
I want item in .divA has the width of 50% of .divA
Edit: Since you don't want it to wrap, but scroll horizontally, you can put it as overflow-x: scroll;
.divA {
background: red;
width: 500px;
display: flex;
justify-content: flex-start;
overflow-x: scroll;
overflow-y: auto;
}
.epi {
min-width: 50%;
background: blue;
}
<div class="divA">
<div class="epi">
<h1>dsds</h1>
<p>sdsds</p>
<img src="img/heart.png" alt="" />
</div>
<div class="epi">
<h1>dsds</h1>
<p>sdsds</p>
<img src="img/heart.png" alt="" />
</div>
<div class="epi">
<h1>dsds</h1>
<p>sdsds</p>
<img src="img/heart.png" alt="" />
</div>
<div class="epi">
<h1>dsds</h1>
<p>sdsds</p>
<img src="img/heart.png" alt="" />
</div>
</div>

nth-child - second img of a div

I have two images inside of a div
<div class="my_div">
<img src="1.jpg" />
<img src="2.jpg" />
</div>
I have tried following css
.my_div img:nth-child(2) { margin-top:130px; }
But this doesn't work? Any idea why?
use display: inherit; on .my_div img:nth-child(2)
.my_div img:nth-child(2) {
margin-top:130px;
display: inherit;
}
<div class="my_div">
<img src="1.jpg" />
<img src="2.jpg" />
</div>

Responsive divs with and image in each

I am trying to done is have a responsive div with 2 pictures centered, one in each div.
What I am want it is to drop down, when the screen is small and not big enought to display them side by side.
At the moment with the below when the screen is smaller it pushes the images into each other.
<style>
.container{width:100%}
.inner_container{float:left;width:50%;}
.img_container{width:250px;margin:0 auto:padding-bottom:5px;}
</style>
<div class="container">
<div class="inner_container">
<div class="img_container">
<img src="left_img.png" width="250" height="70" alt="" border="0">
</div>
</div>
<div class="inner_container">
<div class="img_container">
<img src="right_img.png" width="250" height="70" alt="" border="0">
</div>
</div>
</div>
You're using the wrong styles to do what you're trying to do. Mainly, you've set a fixed width of 250px to your img_container div which is why the images aren't getting scaled down. This the correct way to achieve what you want:
.container {
width: 100%
}
.inner_container {
width: 49%;
display: inline-block;
}
.img_container {
width: 100%;
}
.img_container a img {
width: 100%;
}
<div class="container">
<div class="inner_container">
<div class="img_container">
<a href="http://www.google.co.uk">
<img src="http://lorempixel.com/400/200/" width="250" height="70" alt="" border="0">
</a>
</div>
</div>
<div class="inner_container">
<div class="img_container">
<a href="http://www.google.com">
<img src="http://lorempixel.com/400/200/" width="250" height="70" alt="" border="0">
</a>
</div>
</div>
</div>
With the above code, the images keep on getting scaled down and stay on the same line until the window size is reduced to very small. If you would want them to appear on two separate lines after a particular width, you will need to use media-queries like this:
.container{width:100%}
.inner_container { width: 49%; display: inline-block; }
.img_container { width: 100%; }
.img_container a img { width: 100%; }
#media (max-width: 650px) {
.inner_container { width: 100%; display: block; }
}
<div class="container">
<div class="inner_container">
<div class="img_container">
<img src="http://lorempixel.com/400/200/" width="250" height="70" alt="" border="0">
</div>
</div>
<div class="inner_container">
<div class="img_container">
<img src="http://lorempixel.com/400/200/" width="250" height="70" alt="" border="0">
</div>
</div>
</div>
Set a min-width on the .inner_container
.container {
width:100%;
overflow: hidden;
}
.inner_container {
float:left;
width:50%;
min-width: 250px;
}
.img_container {
width:250px;
margin:0 auto;
padding-bottom:5px;
text-align: center;
}
http://jsfiddle.net/63pnotjc/
When I posted my reply, I didn't notice Fahad, Show code snippet link.
Thank you both for your help, this is the css code I went with in the end.
.container{width:100%;overflow:hidden;}
.inner_container{display:inline-block;width:49%;}
.img_container{width:250px;margin:0 auto;text-align:center;padding-bottom:5px;}
#media (max-width:501px){
.inner_container{display:block;width:100%;}
}
Once again thank you both for your help :)

Y-scrollbar and scrolling images to left side

I have two questions
1) How can I remove a y-scrollbar.
2) How can I make images scroll to the left instead of down?
Any advise? Any help is much appreciated.
Here is my example:
HTML
<div class="ProjectGallery">
<img src="images/Thumb/10.jpg" data-title="<?=$title10?>" />
<img src="images/Thumb/11.jpg" data-title="<?=$title11?>" />
<img src="images/Thumb/12.jpg" data-title="<?=$title12?>" />
<img src="images/Thumb/14.jpg" data-title="<?=$title14?>" />
<img src="images/Thumb/15.jpg" data-title="<?=$title15?>" />
<img src="images/Thumb/17.jpg" data-title="<?=$title17?>" />
<img src="images/Thumb/18.jpg" data-title="<?=$title18?>" />
</div>
CSS
.ProjectGallery{height:300px;overflow:scroll;float:left;}
.ProjectGallery img{float:left;width:100%;height:100px;}
<div class="gallery-container">
<div class="gallery">
<div class="thumbnails">
<img src="images.png"/>
<img src="images.png"/>
<img src="images.png"/>
<img src="images.png"/>
<img src="images.png"/>
<img src="images.png"/>
</div>
</div>
</div>
.gallery
{
border: 1px solid black;
height: 120px;
width: 200px;
overflow: hidden;
overflow-x: scroll;
}
.thumbnails
{
width: 1000px;
}
.gallery-container img
{
width: 200px;
height: auto;
}
.thumbnails img
{
width: auto;
height: 100px;
display: block;
float: left;
border: 1px solid #ddd;
margin: 1px;
}
try this
Try this
HTML
<div class="ProjectGallery">
<img src="images/Thumb/10.jpg" data-title="<?=$title10?>" />
<img src="images/Thumb/11.jpg" data-title="<?=$title11?>" />
<img src="images/Thumb/12.jpg" data-title="<?=$title12?>" />
<img src="images/Thumb/14.jpg" data-title="<?=$title14?>" />
<img src="images/Thumb/15.jpg" data-title="<?=$title15?>" />
<img src="images/Thumb/17.jpg" data-title="<?=$title17?>" />
<img src="images/Thumb/18.jpg" data-title="<?=$title18?>" />
</div>
CSS
.ProjectGallery{height:300px;overflow:scroll;white-space:nowrap}
.ProjectGallery img{width:100%;height:100px;display:inline;}

Resources