I have a grid of 4 images displayed, using Flexbox to align them to everything is centered in all directions. When a user mouses over an image, it uses transform: scale(1.5) to enlarge the image.
Everything works perfect in Chrome and Firefox. But when I view the same page in IE11, things don't work so well.
The first problem is that sometimes the images are distorted (before applying any transformations), yet simply refreshing without changing anything will sometimes fix it.
The second (and bigger) problem comes when applying the transformation, the image is completely distorted.
JS Fiddle Link Here
I've Checked http://caniuse.com/#feat=flexbox and I'm not seeing anything obvious... I'm pretty sure it's a Flexbox issue, because there are times when I'm having issues before any transformation is applied.
EDIT 1
I've noticed that adding min-width:1px; on the img seems to fix the scaling issue, but throws off the centering on mouse-out. JS Fiddle Update.
$("#kitty").hover(function() {
$(this).css({
'transform': 'scale(1.5)',
'z-index': 1
});
},
function() {
$(this).css({
'transform': 'scale(1)',
'z-index': 0
});
}
);
.img-container {
padding: 4px;
height: 100%;
border: 5px;
border-color: black;
border-style: solid;
}
.top .img-container {
display: flex;
flex-flow: row nowrap;
align-items: center;
}
.bottom .img-container {
display: flex;
flex-flow: row nowrap;
align-items: center;
}
img {
max-width: 100%;
max-height: 100%;
height: auto;
width: auto;
}
.col-sm-6 {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.row-inner {
background-color: orange;
height: 45vh;
width: auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row top">
<div class="row-inner">
<div class="col-sm-6">
<div class="img-container">
<img src="http://i63.tinypic.com/dqruoj.jpg" class="img-responsive" id="kitty">
</div>
</div>
<div class="col-sm-6">
<div class="img-container">
<img src="http://i64.tinypic.com/vrbhqx.jpg" class="img-responsive">
</div>
</div>
</div>
</div>
<div class="row bottom">
<div class="row-inner">
<div class="col-sm-6">
<div class="img-container">
<img src="http://i66.tinypic.com/2j0bn9e.jpg" class="img-responsive">
</div>
</div>
<div class="col-sm-6">
<div class="img-container">
<img src="http://i63.tinypic.com/35kivqw.jpg" class="img-responsive">
</div>
</div>
</div>
</div>
BEFORE
During Mouse Over
Related
I am trying to create a split screen scroll.
I need to position the image from the first column exactly parallel to the image from the second column.
It has to start and finish with both images completly visible on the screen.
My problem is that when it starts and finishes the images are not aligned (a bit of one image is not visible).
It only works randomly on some resolutions.
The left column works with the default native browser scroll.
The second column which is fixed positioned is working by taking the the number of pixels scrolled then multiplied by minus one.
https://codepen.io/victoreugen2002/pen/QWdJzdB
$(window).on('scroll', function() {
$(".column-right").css('bottom', $(window).scrollTop() * -1);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="full-page">
<div class="column-left">
<div class="image">
<img src="https://picsum.photos/200/300">
</div>
<div class="image">
<img src="https://picsum.photos/200/300">
</div>
<div class="image">
<img src="https://picsum.photos/200/300">
</div>
</div>
<div class="column-right">
<div class="image">
<img src="https://picsum.photos/200/300">
</div>
<div class="image">
<img src="https://picsum.photos/200/300">
</div>
<div class="image">
<img src="https://picsum.photos/200/300">
</div>
</div>
</div>
<style>
.full-page .column-left {
margin-top: 0;
display: flex;
flex-direction: column;
justify-content: space-between;
width: 100%;
box-sizing: border-box;
}
.full-page .column-right {
justify-content: space-between;
width: 100%;
box-sizing: border-box;
padding-left: 30px;
padding-right: 30px;
width: 50%;
left: 50%;
position: fixed;
display: flex;
flex-direction: column-reverse;
bottom: 0;
}
.image {
width:496px;
}
.image img {
width: 100%;
}
</style>
I try to develop website for my portfolio. I want to do something like that :
But I've some problem with the 3 icons for Twitter/Instagram and Deviantart. To put the icons like that, I use the flexbox in html. Currently, I've that :
#conteneur {
display: flex;
justify-content: space-between;
}
<div id="conteneur">
<div class="element1">
<img src="https://zupimages.net/up/21/29/vbxh.png">
</div>
<div class="element2">
<img src="https://zupimages.net/up/19/51/4gl0.png">
</div>
<div class="element3">
<img src="https://zupimages.net/up/21/29/dbtc.png">
</div>
</div>
Test with CodePen here : https://codepen.io/lucbenedet/pen/yLbPMgK
But as you can see, the pictures are too large and when I try to put the pictures to a size of 35px like that :
#conteneur
{
display: flex;
justify-content: space-between;
width: 35px;
}
or
.element1
{
width: 35px;
}
The resize doesn't works...
Someone to show how to do that ?
You can update your CSS with following code.
#conteneur {
display: flex;
justify-content: space-between;
width: 150px;
padding: 10px;
}
#conteneur div img {
width: 35px;
height: 35px;
}
<div id="conteneur">
<div class="element1">
<img src="https://zupimages.net/up/21/29/vbxh.png">
</div>
<div class="element2">
<img src="https://zupimages.net/up/19/51/4gl0.png">
</div>
<div class="element3">
<img src="https://zupimages.net/up/21/29/dbtc.png">
</div>
</div>
You can have some space between icons when you maximize the width of the container
you can reset width on the flex-container to max-content (3 icones shouldnot overflow) and use gap to set a distance in between them.
You could use em for the gap and icon's width to have a coherent render.
Possible example:
#conteneur {
display: flex;
width: max-content;
align-items: center;
margin: auto;
gap: 1.6em;
}
#conteneur div img {
width: 3em;
}
<div id="conteneur">
<div class="element1">
<img src="https://zupimages.net/up/21/29/vbxh.png">
</div>
<div class="element2">
<img src="https://zupimages.net/up/19/51/4gl0.png">
</div>
<div class="element3">
<img src="https://zupimages.net/up/21/29/dbtc.png">
</div>
</div>
possible example from your codepen https://codepen.io/gc-nomade/pen/qBmVjBV
I'm doing some flex-grid and having problems getting inline images to scale their dimensions to match the height of a flex-grown box.
I have a flexbox column where I have a title and a wrapper that will grow to whatever space is leftover. Inside the wrapper is list of images that I would like to all have the same height and be inline. No matter what I do the images end up to the right of the title and outside the dimensions of the flexbox. Any help would be appreciated. Bad drawing included on what I would like vs what I currently get
Link to fiddle: https://jsfiddle.net/oan5fmtb/1/
<div class="container">
<h4>Title</h4>
<div class="imgs">
<img src="..." class="img">
<img src="..." class="img">
<img src="..." class="img">
<img src="..." class="img">
...
</div>
</div>
.container {
height: 170px;
width: 100%;
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
.imgs {
flex: 1;
/* Not sure if I need anything else here */
}
.img {
display: inline;
/* Not sure what to do */
}
Please try this,
.container {height: 170px;width: 100%;border: 1px solid black;}
.imgs {display: flex;}
.img{width:60px;height:60px;margin-right: 10px;}
It works as expected
Found the solution thanks to this answer.
<div class="container">
<h4>Title</h4>
<div class="imgs">
<img src="..." class="img">
<img src="..." class="img">
</div>
</div>
.container {
height: 170px;
width: 100%;
display: flex;
flex-direction: column;
border: 1px solid black;
}
.imgs {
flex: 1;
min-height: 0;
border: 1px solid red;
}
.img {
height: 100%;
width: auto;
}
I found out that a flex item cannot shrink smaller than the size of their content, min-height: 0 will fix this.
Is it possible to crop images to the shortest height of an image in a single row of images? If so, can this be done solely with CSS?
Here is an example of what I'd like to accomplish:
And here is the code I am currently working on:
.container {
width: 100%;
margin: 0 auto;
}
.row {
width: 100%;
background: black;
display: flex;
align-items: center;
overflow: auto;
}
.row .item {
width: 33.33333%;
}
.row img {
display: block;
object-fit: cover;
width: 100%;
}
<div class="container">
<div class="row">
<div class="item">
<img src="https://78.media.tumblr.com/708bb6dcdaf359fd2ea83d11a0b5b4b8/tumblr_oyslstg5xk1unhdoco3_r1_1280.jpg" />
</div>
<div class="item">
<img src="https://78.media.tumblr.com/c49ef0b40483c35ad3b6898c0e037e11/tumblr_oyslstg5xk1unhdoco2_r1_1280.jpg" />
</div>
<div class="item">
<img src="https://78.media.tumblr.com/737456a69c07da1a9a2784506f62dce9/tumblr_oyslstg5xk1unhdoco9_r1_1280.jpg" />
</div>
</div>
</div>
Any solutions or advice?
It's probably best to use JS for this, unless you can process the heights on a backend script and set a height on the container as it is output.
Anyways, here is a little bit of JS that should achieve what you want:
const items = [...document.querySelectorAll('.item')];
const row = document.querySelector('.row');
function normalizeImages(images, container) {
const shortestItem = images.reduce((smallest, element) => {
return element.clientHeight < smallest.clientHeight ? element : smallest;
});
container.style.height = `${shortestItem.clientHeight}px`;
}
normalizeImages(items, row);
window.addEventListener('resize', () => normalizeImages(items, row));
.container {
width: 100%;
margin: 0 auto;
}
.row {
width: 100%;
background: black;
display: flex;
align-items: center;
overflow: hidden;
}
.row .item {
flex-basis: 33.33333%;
}
.row img {
display: block;
width: 100%;
}
<div class="container">
<div class="row">
<div class="item">
<img src="https://78.media.tumblr.com/708bb6dcdaf359fd2ea83d11a0b5b4b8/tumblr_oyslstg5xk1unhdoco3_r1_1280.jpg" />
</div>
<div class="item">
<img src="https://78.media.tumblr.com/c49ef0b40483c35ad3b6898c0e037e11/tumblr_oyslstg5xk1unhdoco2_r1_1280.jpg" />
</div>
<div class="item">
<img src="https://78.media.tumblr.com/737456a69c07da1a9a2784506f62dce9/tumblr_oyslstg5xk1unhdoco9_r1_1280.jpg" />
</div>
</div>
</div>
Note that a small amount of CSS has changed to hide overflow on the .row element
The issue I am facing here has to do with the fact that the total width of the child divs is larger than the width of the parent div. I need the child divs to float to the left of each other even if they overflow the parent div.
I have this HTML:
<div class="gallery_container">
<div id="viewport">
<div class="gallery_img_container">
<img src="images/1/1.png" class="gallery_img">
</div>
<div class="gallery_img_container">
<img src="images/1/2.png" class="gallery_img">
</div>
<div class="gallery_img_container">
<img src="images/1/3.png" class="gallery_img">
</div>
</div>
</div>
And this CSS:
.gallery_container {
width: 70%;
height: 100%;
float: left;
background-color: #171717;
}
#viewport {
height: 100%;
width: 100%;
}
.gallery_img_container {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.gallery_img {
height: 95%;
}
How can I get all divs with of class gallery_img_container to float to the left of each other? I've tried adding float:left .gallery_img_container but it doesn't do anything. They go underneath each other instead of side by side.
Another note is that .gallery_img_container must have the display:flex property
Thanks in advance for any help!
EDIT: .gallery_img_container must have the width:100% property
You have "width:100%;" applied to the ".gallery_img_container" class causing each container to break into next line, remove this and add "float: left;" then it will work.
Edited based on comments.
.gallery_container {
width: 70%;
height: 100%;
background-color: #171717;
}
#viewport {
height: 100%;
width: 100%;
display: flex;
}
.gallery_img_container {
width: 100%;
height: 100%;
display: flex;
flex-direction: row;
justify-content: flex-start;
flex-wrap: wrap;
}
.gallery_img {
height: 95%;
}
<div class="gallery_container">
<div id="viewport">
<div class="gallery_img_container">
<img src="images/1/1.png" class="gallery_img">
</div>
<div class="gallery_img_container">
<img src="images/1/2.png" class="gallery_img">
</div>
<div class="gallery_img_container">
<img src="images/1/3.png" class="gallery_img">
</div>
</div>
</div>
Farasat,
I'm not entirely sure what you are trying to accomplish. Let me see if I can confirm what I think you are seeking. You want to achieve a result where you have a set of images which are, collectively, wider than #viewport, but you want them to keep "piling up" to the right. That is, you don't want them to wrap. If we consider [] the bounds of the viewport and # to be an image, you want (for example), something like this:
[#]##
Is this right?
If so, I think a key thing to note is that your gallery_img_container is of display flex, which means it is a block, not inline, style. This will cause the gallery_img_containers to stack, not flow to the right.
I think all you need to do is to say "white-space: nowrap;" in #viewport (to keep things from wrapping), and then to make gallery_img_container to be of type inline-flex, so that they do not stack.
I'm attaching an example to hopefully demonstrate what I mean (notes: I just grabbed a random image off the web to make this more concrete. Also note that since your gallery_img_container is 100%, each image is the size of the #viewport. I'm not sure if that's what you want).
.gallery_container {
width: 70%;
height: 100%;
background-color: #171717;
}
#viewport {
height: 100%;
width: 100%;
white-space: nowrap;
}
.gallery_img_container {
width: 100%;
height: 100%;
display: inline-flex;
justify-content: center;
align-items: center;
}
.gallery_img {
height: 95%;
}
<div class="gallery_container">
<div id="viewport">
<div class="gallery_img_container">
<img src="https://wildfiregames.com/forum/uploads/monthly_2016_07/elephant.png.d12017f872cf14f8b046706f497701ba.png" class="gallery_img">
</div>
<div class="gallery_img_container">
<img src="https://wildfiregames.com/forum/uploads/monthly_2016_07/elephant.png.d12017f872cf14f8b046706f497701ba.png" class="gallery_img">
</div>
<div class="gallery_img_container">
<img src="https://wildfiregames.com/forum/uploads/monthly_2016_07/elephant.png.d12017f872cf14f8b046706f497701ba.png" class="gallery_img">
</div>
</div>
</div>