Centering 3 different images on top of each other - html

I have 3 images, all images are different widths and in the CSS I'm gonna be controlling the width with a %. Trying to position these images on top of each other + having them centered is proving to be tricky.
Normally to center the images I would just use Transform:translate(-50%, -50%) and set up my width percentage to like 60% and set my left and right 20% all in CSS, but because I'm using a parallax plugin that uses Transform: It cancels out my Transform:translate within the CSS (Chrome inspector shows it with a line through it). I think.
I need a way to center the images, while still let me width % and I can't think of a reliable method.
Fiddle: https://jsfiddle.net/bcabm0ru/3/
ul {
padding-left: 0px;
list-style: none;
}
li {}
.bubbles-one {
position: absolute;
z-index: 2;
}
.image-holder {}
.splash {
z-index: 4;
position: absolute;
margin-top: -15%;
}
.spotlight {
z-index: 3;
position: absolute;
}
.man {
z-index: 1;
position: absolute;
}
<section class="falling-person">
<div class="bubbles-one"><img src="./assets/images/bubble_01edit.png" alt="" class="img-fluid"></div>
<div class="container">
<dov class="row">
<div class="col-12">
<div class="image-holder">
<ul class="falling-scene">
<li class="layer" id="bubble_splash-layer"><img src="http://www.sharksharkshark.net/testing/assets/images/bubble_splash.png" alt="" class="mx-auto d-block img-fluid splash rellax"></li>
<li class="layer" id="spotlight-layer"><img src="http://www.sharksharkshark.net/testing/assets/images/spotlight.png" alt="" class="mx-auto d-block img-fluid spotlight rellax"></li>
<li class="layer" id="man-layer"> <img src="http://www.sharksharkshark.net/testing/assets/images/man.png" alt="" class="img-fluid man rellax"></li>
</ul>
</div>
</div>
</dov>
</div>

You can tell me if you don't want the HTML to be different, but I found this way more clean and easier to handle. What do you think? JSFiddle
HTML
<section class="falling-person">
<div class="image-wrapper">
<div class="layer" id="bubble_splash-layer">
<img class="splash" src="http://www.sharksharkshark.net/testing/assets/images/bubble_splash.png" alt="splash" />
</div>
<div class="layer" id="spotlight-layer">
<img class="spotlight" src="http://www.sharksharkshark.net/testing/assets/images/spotlight.png" alt="spotlight" />
</div>
<div class="layer" id="man-layer">
<img class="man" src="http://www.sharksharkshark.net/testing/assets/images/man.png" alt="man" />
</div>
</div>
</section>
CSS
body,
html {
height: 100%;
width: 100%;
margin: 0;
}
.image-wrapper {
width: 100%;
}
img {
width: 200px;
position: absolute;
left: 0;
right: 0;
margin: auto;
}
.splash {
position: absolute;
margin-top: -15%;
z-index: 4;
}
.spotlight {
position: absolute;
z-index: 3;
}
.man {
position: absolute;
z-index: 1
}

Looks like you are using bootstrap 4. You should be able to just change your li tags to:
<li class="layer d-flex justify-content-center" id="bubble_splash-layer">
<img src="http://www.sharksharkshark.net/testing/assets/images/bubble_splash.png" alt="" class="mx-auto d-block img-fluid splash rellax">
</li>
<li class="layer d-flex justify-content-center" id="spotlight-layer"><img src="http://www.sharksharkshark.net/testing/assets/images/spotlight.png" alt="" class="mx-auto d-block img-fluid spotlight rellax">
</li>
<li class="layer d-flex justify-content-center" id="man-layer">
<img src="http://www.sharksharkshark.net/testing/assets/images/man.png" alt="" class="img-fluid man rellax">
</li>

Related

Center Image Over Image Responsive site

I am trying to position a small image in the center of a bibber one. Both images are inside a Bootstrap Column.
<div className="row justify-content-center my-5 ">
<div className="col-xs-10 col-sm-6 my-auto mx-auto">
<Fade left duration={1000} delay={1000} fraction={0.1} >
<div className="father">
<img height="110%" width="100%" className="img-fluid biggerImg" src="/img/edificios.jpg" alt="edificios"/>
<img src="/img/logo02.png" alt="logo" className="logo"/>
</div>
</Fade>
</div>
And this is the css.
.padreImagenes{
/* background-image: url("../../assets/img/edificios.jpg"); */
text-align: center;
}
.biggerImg{
position: relative;
opacity: 0.8;
}
.logo{
position: absolute;
/* position: absolute;
transform: translate(-200%, 70%); */
/* position: absolute;
top: 60px;
left: 80px; */
}
As you can see in commented CSS code, I have tried setting the smaller image as absolute, and playing around with top, left, even transform/translate. The problem is that, when the site adapts to user screen size, It does not remain centered.
Combining both images with photoshop is not an option, since I want to apply an effect to the "smaller image".
Thanks,
try:
.logo {
position: absolute;
top:50%;
left:50%;
transform:translateX(-50%) translateY(-50%);
}
div {position:relative; display:inline-block;}
img {display:block;}
.logo {
position: absolute;
top:50%;
left:50%;
transform:translateX(-50%) translateY(-50%);
}
<div>
<img src="https://www.kurzweilai.net/images/Naam-Limits-of-Earth-Part1-001-earth-600x600.jpg" alt="">
<img src="https://blogs.salleurl.edu/sites/default/files/blogs/emprendedores/chrome_hacked_Pwnium-300x300.jpg" alt="" class="logo">
</div>
You can set the images container to display: flex and use the flex attributes to center the elements.
However, I haven't tested it with bootstrap, so there might be some styles conflicts.
.father {
display: flex;
align-items: center;
justify-content: center;
}
.logo {
position: absolute;
}
<div class="row justify-content-center my-5 ">
<div class="col-xs-10 col-sm-6 my-auto mx-auto">
<div class="father">
<img height="110%" width="100%" class="img-fluid biggerImg" src="https://picsum.photos/200/150
" alt="edificios"/>
<img src="https://picsum.photos/100/100
" alt="logo" class="logo"/>
</div>
</div>

Bootstrap/CSS - How to put various images over a long image (that is behind them)?

I'm trying to put six .png images over a long, tray-like image. I don't know if my structure is wrong or if bootstrap is in conflict with CSS when I play around with position: absolute and position: relative (which I later removed). This is the result I expected:
However, this is my current status:
Here's my code.
HTML code:
<div class="d-flex flex-row mt-2">
<div class="">
<img class="tray" src="../../../assets/images/Generals/Icon_1.png" alt="">
</div>
<div class="">
<img class="tray-icon" src="../../../assets/images/Generals/Icon_2.png" alt="">
</div>
<div class="">
<img class="tray-icon" src="../../../assets/images/Generals/Icon_3.png" alt="">
</div>
<div class="">
<img class="tray-icon" src="../../../assets/images/Generals/Icon_4.png" alt="">
</div>
<div class="">
<img class="tray-icon" src="../../../assets/images/Generals/Icon_5.png" alt="">
</div>
<div class="">
<img class="tray-icon" src="../../../assets/images/Generals/Icon_6.png" alt="">
</div>
<div class="">
<img class="tray-icon" src="../../../assets/images/Generals/Icon_7.png" alt="">
</div>
</div>
CSS code:
.tray-icon{
width: 70%;
transition: transform .2s;
}
.tray{
width: 100%;
}
.tray-icon:hover {
transform: scale(1.5);
}
Any idea how can I get closer to the expected result?
Given the info/code you've placed in your question:
Give each image: display: block; so that they each moves to a new line.
Center everything. Might be a mixture of text-align: center; which typically centers it's inline/inline-block children (unless over-ridden), or try using margin: 0 auto; which typically centers inline-block/block elements.
At this point everything should be centered in .d-flex.flex-row. Move the dark blue image up into position by giving it a negative margin-top: margin: -40px auto 0;. You could also use position: relative; top: -40px;, or transform: translateY(-40px);. Pick your poison.
Your code should something like the example code I've attached below. Some rules won't apply as well, like box-shadow (if you're using on on an image for example).
.d-flex.flex-row {
margin: 0 auto;
padding: 0;
text-align: center;
}
/* this is the dark blue square. */
.d-flex.flex-row::after {
content: "";
background-image: url(https://imagecdn.app/v1/images/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1525923838299-2312b60f6d69?width=500&height=70);
width: 500px;
height: 70px;
border-top-right-radius: 15px;
border-bottom-left-radius: 15px;
margin: -40px auto 0;
display: block;
background-size: cover;
}
/* your image containers */
.d-flex.flex-row > div {
display: inline-block;
margin: 10px;
border-top-right-radius: 15px;
border-bottom-left-radius: 15px;
box-shadow: 2px 5px 10px rgba(0,0,0,0.3);
overflow: hidden;
}
/* your images */
.d-flex.flex-row > div img {
display: block;
}
<div class="d-flex flex-row mt-2">
<div class="">
<img class="tray" src="https://imagecdn.app/v1/images/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1525923838299-2312b60f6d69?width=50&height=50" alt="">
</div>
<div class="">
<img class="tray" src="https://imagecdn.app/v1/images/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1525923838299-2312b60f6d69?width=50&height=50" alt="">
</div>
<div class="">
<img class="tray" src="https://imagecdn.app/v1/images/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1525923838299-2312b60f6d69?width=50&height=50" alt="">
</div>
<div class="">
<img class="tray" src="https://imagecdn.app/v1/images/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1525923838299-2312b60f6d69?width=50&height=50" alt="">
</div>
<div class="">
<img class="tray" src="https://imagecdn.app/v1/images/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1525923838299-2312b60f6d69?width=50&height=50" alt="">
</div>
<div class="">
<img class="tray" src="https://imagecdn.app/v1/images/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1525923838299-2312b60f6d69?width=50&height=50" alt="">
</div>
</div>

Fill width of a div containing a horizontal array of images with css

I have a container div with multiple varying-width, uniform-height images. The images are horizontally arranged with no gaps between them.
What I have so far:
#imageContainer {
width: 80%;
border: 1px solid blue;
position: relative;
left: 50%;
transform: translateX(-50%);
}
#images {
display: flex;
width: 80%;
position: relative !important;
margin: 2px;
}
#imageContainer img {
display: inline-block;
position: relative;
margin: 1px;
}
<div id="imageContainer">
<div id="images">
<img src="https://dummyimage.com/400x100/000/fff" alt="">
<img src="https://dummyimage.com/320x100/000/fff" alt="">
<img src="https://dummyimage.com/420x100/000/fff" alt="">
<img src="https://dummyimage.com/540x100/000/fff" alt="">
</div>
</div>
I would like for all of the images to scale to fit within my div, filling it, but I can't seem to find where I can do this with multiple images.
I question is basically this one but with a twist of also scaling to fit.
Unless you want a gap in your box you should remove width/position from the inner #images container. To make the images scale down you can add a min-width. If you want the images to not distort add an object-fit:
#imageContainer {
width: 80%;
border: 1px solid blue;
position: relative;
left: 50%;
transform: translateX(-50%);
}
#images {
display: flex;
margin: 2px;
}
#imageContainer img {
display: inline-block;
position: relative;
margin: 1px;
/* Important bits: */
min-width: 0;
object-fit: contain;
}
<div id="imageContainer">
<div id="images">
<img src="https://dummyimage.com/400x100/000/fff" alt="">
<img src="https://dummyimage.com/320x100/000/fff" alt="">
<img src="https://dummyimage.com/420x100/000/fff" alt="">
<img src="https://dummyimage.com/540x100/000/fff" alt="">
</div>
</div>
(Btw, centering using left + transform can cause blurriness in some rendering engines.)
I prefer using Bootstrap for most of my front-end styling as they provide lots of nifty "features" that make it easy for me to create a nice looking front-end without having to spend hours with CSS trying to get it looking perfect or making it scalable to multiple viewports.
Hence, here is how I would solve it using Bootstrap-4. (Here is a Codepen link)
<div class="container">
<div class="row outline-primary">
<div class="col">
<img src="https://dummyimage.com/400x100/000/fff" class="img-fluid h-100">
</div>
<div class="col">
<img src="https://dummyimage.com/320x100/000/fff" class="img-fluid h-100">
</div>
<div class="col">
<img src="https://dummyimage.com/420x100/000/fff" class="img-fluid h-100">
</div>
<div class="col">
<img src="https://dummyimage.com/540x100/000/fff" class="img-fluid h-100">
</div>
</div>
</div>

Center stacked-images horizontally

I need to display 4 images centered in the screen. I need this images must be stacked one of top another. I resolved the stack part:
.img-container { position: relative; }
.img-container .top {
position: absolute;
top: 0;
left: 0;
z-index: 1;
}
<div class="img-container">
<img src="icon-1.png">
<img class="top" src="icon-2.png">
<img class="top" src="icon-3.png">
<img class="top" src="icon-4.png">
</div>
<div >
<img class="img-responsive center-block " src="another-image-below.png"
style="display: block; margin: 0 auto;">
</div>
That gives me the 4 images stacked BUT now I need to center all 4 of them (horizontally). The "another-image-below.png" is just another image that it is also centered but that must be placed below the 4 stacked images.
It sound simple, and I tried everything but I cannot resolve it.
How can I achieve that?
Thanks in advance.
EDIT:
https://jsfiddle.net/b5p8dkcu/4/
You don't need the z-index in your example, unless you have another element somewhere that has to be behind the images.
You can just add align="center" to the <div align="center" class="img-container">.
EDIT:
<html>
<style>
.img-container {
position: relative;
top: 0;
left: 0;
}
.top {
}
<div align="center" class="img-container">
<img src="icon-1.png">
<img class="top" src="icon-2.png">
<img class="top" src="icon-3.png">
<img class="top" src="icon-4.png">
</div>
<div >
<img class="img-responsive center-block " src="6.png"
style="display: block; margin: 0 auto;">
</div>
If you need them to be vertically on top of each other:
<style>
.img-container {
position: relative;
top: 0;
left: 0;
}
.top {
display: block;
}
If you need them to be literally on top of each other:
<style>
.img-container {
position: relative;
top: 0;
left: 0;
}
.top {
position: absolute;
}

How to put image tiles properly without colum gap or row gap in between using only CSS?

I'm new to HTML and CSS. For one of my projects, I need to put 16 images into a 4x4 grid of tiles on a webpage. These tiles cannot have gaps between them, and they need to stretch to fill the browser from side to side. They also should only scroll vertically. We are only allowed to use JavaScript or JQuery so I can only use HTML and CSS.
I wrote 4 div elements, each represents a row; inside each div, a span element holds 4 images - that's how I made the 4x4 grid. A code snippet looks like this:
/* One row in a div*/
<div class="map">
<span>
<img src="map_images/1.png">
<img src="map_images/2.png">
<img src="map_images/3.png">
<img src="map_images/4.png">
</span>
</div>
I also wrote a navigation bar that should float above the background images in the upper right corner:
/* 4 div elements of 4 rows before this code*/
<div id="nav">
<div>Foo</div>
<div>Boo</div>
</div>
For the above code, my stylesheet looks like this:
.map{
margin:0;
padding:0;
}
#nav {
position: absolute;
top: 0;
right: 0;
z-index: 10;
}
However, I've encountered several problems at this point.
First, I still have column gaps and row gaps between all 16 images. No matter what values I set map margin and padding to, nothing changes. I even tried negative values, still nothing changed. Can someone tell me how to go about this problem, eliminating all gaps?
Secondly, I googled and learned that z-index can be used to make div float above background; however, this is no working here and it seems that div #nav stays in the upper right corner as a separate div that does take up space, instead of floating above. Any suggestions on this?
Float left and set the width to 25%. Also I show below how to create a floating menu using the :hover pseudo-class.
.map div img {
width: 25%;
float:left;
display: inline-block;
}
#nav {
width: 50px;
background-color: grey;
}
#nav ul {
margin: 0;
padding: 0;
width: 50px;
background-color: grey;
position: absolute;
display:none;
}
#nav:hover ul, #nav ul:hover {
display:block;
}
<div id="nav">
Menu
<ul>
<li>Foo</li>
<li>Boo</li>
</ul>
</div>
<div class="map">
<div class="row">
<img src="http://lorempixel.com/100/100/">
<img src="http://lorempixel.com/100/100/">
<img src="http://lorempixel.com/100/100/">
<img src="http://lorempixel.com/100/100/">
</div>
<div class="row">
<img src="http://lorempixel.com/100/100/">
<img src="http://lorempixel.com/100/100/">
<img src="http://lorempixel.com/100/100/">
<img src="http://lorempixel.com/100/100/">
</div>
<div class="row">
<img src="http://lorempixel.com/100/100/">
<img src="http://lorempixel.com/100/100/">
<img src="http://lorempixel.com/100/100/">
<img src="http://lorempixel.com/100/100/">
</div>
<div class="row">
<img src="http://lorempixel.com/100/100/">
<img src="http://lorempixel.com/100/100/">
<img src="http://lorempixel.com/100/100/">
<img src="http://lorempixel.com/100/100/">
</div>
</div>
I think you are looking for something like this? See fiddle http://jsfiddle.net/DIRTY_SMITH/q12bh4se/4/
Snippet :
body {
margin: 0px;
}
div {
width: 50%;
float: left;
}
img {
width: 50%;
float: left;
}
.top-left {
z-index: 9999;
position: absolute;
top: 0;
left: 0;
color: white;
}
.top-right {
z-index: 9999;
position: absolute;
top: 0;
right: 0;
color: white;
}
<h1 class="top-left">Top Left</h1>
<h1 class="top-right">Top Right</h1>
<div class="row-1-col-1">
<img src="http://lorempixel.com/g/200/200/">
<img src="http://lorempixel.com/200/200/sports/">
<img src="http://lorempixel.com/200/200/sports/1/">
<img src="http://lorempixel.com/200/200/sports/Dummy-Text/">
</div>
<div class="row-1-col-2">
<img src="http://lorempixel.com/g/200/200/">
<img src="http://lorempixel.com/200/200/sports/">
<img src="http://lorempixel.com/200/200/sports/1/">
<img src="http://lorempixel.com/200/200/sports/Dummy-Text/">
</div>
<div class="row-2-col-3">
<img src="http://lorempixel.com/g/200/200/">
<img src="http://lorempixel.com/200/200/sports/">
<img src="http://lorempixel.com/200/200/sports/1/">
<img src="http://lorempixel.com/200/200/sports/Dummy-Text/">
</div>
<div class="row-3-col-3">
<img src="http://lorempixel.com/g/200/200/">
<img src="http://lorempixel.com/200/200/sports/">
<img src="http://lorempixel.com/200/200/sports/1/">
<img src="http://lorempixel.com/200/200/sports/Dummy-Text/">
</div>
All I had to do was set float: left and width: 25% on the images in CSS
.map img{
float: left;
width: 25%;
}
DEMO