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>
Related
This question already has answers here:
Centering in CSS Grid
(9 answers)
Closed 1 year ago.
I am making my first html/css website and I have the start of a skeleton with placeholder images and icons. I want the icons with text, to each be centered within their respective column. I'm using a CSS grid to set up the columns.
.content-items-wrapper {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
.content-item-wrapper {
position: relative;
}
.content-img-background {
height: 350px;
width: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.img-text-wrapper {
position: absolute;
top: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
text-align: center;
padding-left: 100px;
padding-right: 100px;
}
<div class="master-content-wrapper">
<div class="content-items-wrapper">
<div class="content-item-wrapper">
<div class="content-img-background" style="background-image: URL(images/blue-placeholder.jpg)"></div>
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="images/wrench-placeholder.png">
</div>
<div class="subtitle">
Services
</div>
</div>
</div>
<div class="content-item-wrapper">
<div class="content-img-background" style="background-image:URL(images/white-placeholder.jpg)"></div>
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="images/computer-placeholder.png">
</div>
<div class="subtitle">
Technicians
</div>
</div>
</div>
<div class="content-item-wrapper">
<div class="content-img-background" style="background-image:URL(images/red-placeholder.jpg)"></div>
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="images/paper-placeholder.png">
</div>
<div class="subtitle">
Reviews
</div>
</div>
</div>
</div>
I tried different paddings and tweaking some other things but it never gets exactly in the center of the three vertical columns. The icon with text I'm referring to is the ".img-text-wrapper" div.
If we put some background color and border to some of the elements we can more clearly see what is going on:
The absolutely positioned elements' contents are centered within themselves but not within their parent elements. To achieve that we need to display the parents as flex with justification and alignment centered. Also, the div giving the background to each of these elements does not seem to have any particular meaning other than providing a background image so that is removed and the background is put on the parent in this snippet which gives this result (on wide screens see note):
.content-items-wrapper {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
.content-item-wrapper {
position: relative;
border-style: solid;
height: 350px;
width: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-color: pink;
display: flex;
justify-content: center;
align-items: center;
}
.content-img-background {
height: 350px;
width: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-color: pink;
}
.img-text-wrapper {
position: absolute;
top: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
text-align: center;
padding-left: 100px;
padding-right: 100px;
background-color: lime;
}
<div class="master-content-wrapper">
<div class="content-items-wrapper">
<div class="content-item-wrapper" style="background-image: URL(images/blue-placeholder.jpg)">
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="https://i.stack.imgur.com/Iynpe.jpg">
</div>
<div class="subtitle">
Services
</div>
</div>
</div>
<div class="content-item-wrapper" style="background-image:URL(images/white-placeholder.jpg)">
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="https://i.stack.imgur.com/Iynpe.jpg">
</div>
<div class="subtitle">
Technicians
</div>
</div>
</div>
<div class="content-item-wrapper" style="background-image:URL(images/red-placeholder.jpg)">
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="https://i.stack.imgur.com/Iynpe.jpg">
</div>
<div class="subtitle">
Reviews
</div>
</div>
</div>
</div>
(Note that on smaller displays the cells shrink to fit - this needs correction for full responsiveness - the square can't be given a fixed px dimension)
Sorry i removed a lot of the css as this is not necessary for the answer.
.content-img-background {
height: 350px;
width: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.column {
float: left;
width: 30%;
}
div {
text-align: center;
}
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="column">
<div style= "background-image: URL(images/blue-placeholder.jpg)">
<img src="images/wrench-placeholder.png">
</div>
<div class="subtitle">
Services
</div>
</div>
<div class="column">
<div style= "background-image:URL(images/white-placeholder.jpg)">
<img src="images/computer-placeholder.png">
</div>
<div class="subtitle">
Technicians
</div>
</div>
<div class="column">
<div style= "background-image:URL(images/red-placeholder.jpg)">
<img src="images/paper-placeholder.png">
</div>
<div class="subtitle">
Reviews
</div>
</div>
</div>
</div>
</body>
</html>
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 had to change the logo's resolution to at least be able to see the logo (format was 3400x1716) to 99x50 for overlapping the picture and added a text with the logo.
I set the pictures that are supposed to get superimposed to 300 height and 100% width to fill out the rest of the page, but that is shown in my code.
The end product will be that I will be able to hover over the picture/logo and the text appears.
My problem is that I can't see the logo nor the text that should superimpose the picture.
In total for 12 pictures with 12 different text's but the same logo.
.portfolio-items-wrapper {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
.portfolio-item-wrapper {
position: relative;
}
.portfolio-img-background {
height: 300px;
width: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.img-text-wrapper {
position: absolute;
top: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
text-align: center;
padding-left: 100%;
padding-right: 100%;
}
<div class="content-wrapper">
<div class="portfolio-items-wrapper">
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background- image:url(images/portfolio1.jpg)"></div>
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="images/logos/thought.png">
</div>
<div class="subtitle">
Using a different approach than the NORM!
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background- image:url(images/portfolio2.jpg)"></div>
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="images/logos/thought.png">
</div>
<div class="subtitle">
Everything starts with a THOUGHT!
</div>
</div>
</div>
</div>
</div>
You can use the approach you started using, that is setting a background-image to your parent container element, and then you can position the text and logo elements using flexbox.
img {
width:50px;height:50px;
}
div {
background-image:url('https://static-cse.canva.com/image/1578/RoyalBlue_Set1_23.5dfc6872.png');
background-size:contain;
background-repeat:no-repeat;
background-position:center center;
width:300px;height:300px;
display:flex;align-items:center;flex-direction:column;justify-content:center;
color:#FFF;font-size:36px;
}
<div>
<img src="https://assets.codepen.io/5200861/internal/avatars/users/default.png">
<h3>some text here</h3>
</div>
I'm trying to have 1 image on the top with 2 images below it spanning half the width of the image on top. The problem I'm encountering are aligning issues with the 2 images in which they don't fit nicely below the top image but spaced perfectly to the sides. I'm trying to have the 2 images be below the top image perfectly aligned in the center with no spaces below. As I shrink the window, that is when it looks like I want it to on a full screen except without the spaces. I also want them perfectly aligned in the center of the screen.
https://jsfiddle.net/voryuja8/
.first {
display: flex;
}
.first img {
margin: auto;
max-width: 800px;
}
.second {
display: flex;
}
.second img {
margin: auto;
flex: 1;
max-width: 400px;
}
<div class="first">
<img src="https://sarahannephoto.files.wordpress.com/2015/01/devyn_015.jpg?w=1008" alt="">
</div>
<div class="second">
<img src="http://preen.inquirer.net/files/2016/05/preen-emily-oberg-complex-e1463660455785.jpg" alt="">
<img src="http://preen.inquirer.net/files/2016/05/preen-emily-oberg-complex-e1463660455785.jpg" alt="">
</div>
Just remove margin:auto from the images and use justify-content: center in the flex containers.
.first {
display: flex;
justify-content: center;
}
.first img {
max-width: 800px;
}
.second {
display: flex;
justify-content: center;
}
.second img {
flex: 1;
max-width: 400px;
}
<div class="first">
<img src="https://sarahannephoto.files.wordpress.com/2015/01/devyn_015.jpg?w=1008" alt="">
</div>
<div class="second">
<img src="http://preen.inquirer.net/files/2016/05/preen-emily-oberg-complex-e1463660455785.jpg" alt="">
<img src="http://preen.inquirer.net/files/2016/05/preen-emily-oberg-complex-e1463660455785.jpg" alt="">
</div>
This might be a bit better, as it doesn't rely on setting pixel values for anything: https://jsfiddle.net/voryuja8/1/
HTML:
<div class="second">
<div class="flex-child">
<img src="http://preen.inquirer.net/files/2016/05/preen-emily-oberg-complex-e1463660455785.jpg" alt="">
</div>
<div class="flex-child">
<img src="http://preen.inquirer.net/files/2016/05/preen-emily-oberg-complex-e1463660455785.jpg" alt="">
</div>
</div>
CSS:
img {
max-width: 100%;
}
.second {
display: flex;
}
.flex-child {
flex-grow: 1;
flex-shrink: 1;
}
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