Center Image Over Image Responsive site - html

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>

Related

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>

When i resize my border my image keeps going up to the top?

Why does my image approach the top of the browser when i resize it, im trying to make responsive for mobile but i cant get it work. Do someone have an idea of what im doing wrong to make this work?
.background-1 {
width:100%;
height: 100%;
overflow:hidden;
}
.title {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #a57354;
text-align: center;
}
<div class="background-1">
<img src="Image-1.png" class="img" />
<div class="title">
<div class="info">
<img class="wow rotateIn img-logo" src="logo.png">
<h4 class="wow fadeinUp"> DIN PERSONLIGA BARBERARE I GÄVLE </H4>
</div>
</div>
</div>
Please check if this helps you .. i have added img-fluid class to both images. thanks
add position:relative to .background-1 class.
if you dont put this then your div which has position absolute will move based on the window. thanks
.background-1 {
width:100%;
height: 100%;
overflow:hidden;
position:relative
}
.title {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #a57354;
text-align: center;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
<div class="background-1">
<img src="https://cdn.colorlib.com/shapely/wp-content/uploads/sites/12/2016/03/photo-1422568374078-27d3842ba676-1.jpg" class="img img-fluid" />
<div class="title">
<div class="info">
<img class="wow rotateIn img-logo img-fluid" src="https://www.freelogodesign.org/Content/img/logo-ex-7.png">
<h4 class="wow fadeinUp"> DIN PERSONLIGA BARBERARE I GÄVLE </H4>
</div>
</div>
</div>
Use div instead of img and set your logo as div background. You could have better control on div in your page and It's more standard.
The aspect ratio of your image seems incorrect for mobile displays.
Would suggest you use a different image for mobile, which has height > width. this will lead to the image stretching (bad ux).
If you still want this image to fill the entire screen, then use position: absolute and set the height to 100%;

Centering 3 different images on top of each other

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>

Responsive text overlay on flexbox image gallery [duplicate]

This question already has answers here:
Vertical align middle and centered text on top of image
(2 answers)
Closed 5 years ago.
So i have this code to display image gallery. I want to place "box-text" class on the middle of each image. But if i want use position: relative it doesn't work. Text doesn't want to go higher than the bottom of the image, no matter how I set the top property in css.
<div class="container">
<div class="box">
<img src="1.jpg" class="img-responsive">
<div class="box-text"><h2>Some text</h2><h3>other text</h3></div>
</div>
<div class="box">
<img src="2.jpg" class="img-responsive">
<div class="box-text"><h2>Some text</h2><h3>other text</h3></div>
</div>
<div class="box">
<img src="3.jpg" class="img-responsive">
<div class="box-text"><h2>Some text</h2><h3>other text</h3></div>
</div>
</div>
My css styles:
.container{
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
.box img{
z-index: 1;
}
.box-text{
position: relative;
top:50%;
left: 50%;
z-index: 2;
}
Use position: absolute instead? You can also use transform: translate to help with the centering:
.box {
position: relative;
}
.box-text{
position: absolute;
top:50%;
left: 50%;
z-index: 2;
transform: translate(-50% -50%);
}

vertical align text on image

I know this question has been asked a lot, but I haven't been able to find a solution among the answers. I'm trying to center a text on an image, but I'm having some trouble with the vertical alignment. This is my code:
<div class="col-sm-12 col-md-12 col-lg-12 main_category_container">
<div class="col-sm-4 col-md-4 col-lg-4">
<div class="wrap">
<h3 class="sub_category_title">Centered text</h3>
<img src="some image">
</div>
</div>
</div>
and
.wrap {
height:auto;
margin: auto;
text-align:center;
position:relative;
}
h3.sub_category_title {
vertical-align: middle;
}
Right now the text is horizontally centered above the image, but I can't figure out how to vertically align it in the middle of the image.
Thanks in advance!
Generally if you're trying to put one element overlapping another, you'll end up using position: absolute or position: relative - otherwise, the contents will naturally arrange themselves in a block flow.
You could try something like this:
.image-wrapper {
position: relative;
text-align: center;
width: 300px; /* change or remove as needed */
margin: auto;
}
.image-link { display: block; }
.image-text {
position: absolute;
top: 50%;
left: 0;
right: 0;
margin: auto;
/* The rest of this is just for this demo,
you can change it for your situation. */
font-weight: bold;
color: white;
font-family: sans-serif;
background: rgba(0, 0, 0, 0.5);
}
<div class="image-wrapper">
<a class="image-link" href="#">
<img class="image" src="http://loremflickr.com/300/200" alt="kitten!">
<h3 class="image-text">A Centered Label</h3>
</a>
</div>