I have three images. I want to combine them
I am referring to this link
https://www.w3schools.com/css/css_positioning.asp#:~:text=An%20element%20with%20position%3A%20absolute,moves%20along%20with%20page%20scrolling.
I am trying to achieve this three combine images
I tried static and relative position but they did not work
.object-left, .main-image {
position: absolute;
}
.object-right , .main-image{
position: absolute; //here I am using comma but not work
}
.cshtml
.object-left,
.main-image .object-right {
position: absolute;
}
<div class="container-fluid">
<div class="col-md-4 image">
<img class="object-left" src="~/Graphics/Services Page/obj1.svg" style="width:50px;height:50px;" /> //1 image
<img class="main-image" src="~/Graphics/Services Page/Mobile app developement.svg" /> //2 image
<img class="object-right" src="~/Graphics/Services Page/obj2.svg" style="width:50px;height:50px;" /> //3 image
</div>
<div class="col-md-6" style="margin-top:100px;">
<h2>Content</h2>
<p class="description">asd</p>
</div>
</div>
The problem is that when you use absolute positioning, the objects start at the upper-left corner of the parent (i.e. location 0x0), so all your three images appear on top of each other. All you need to do is tell them where they should be by adding the left property. The first image can stay at left=0, so you don't need to do anything. The second image must start at the width of the first image, left=50px in my example below. The third image must start at the total width of the fist and second image, left=100px in my example below.
Also remember that since you used absolute positioning on all three images and the parent doesn't have any other content, it will collapse. So you need to give it the height of the tallest image.
.object-left {
position: absolute;
}
.main-image {
position: absolute;
left: 50px;
}
.object-right {
position: absolute;
left: 100px;
}
.image {
height: 100px;
}
<div class="container-fluid">
<div class="col-md-4 image">
<img class="object-left" src="http://placehold.it/50x50" />
<img class="main-image" src="http://placehold.it/50x100" />
<img class="object-right" src="http://placehold.it/50x50" />
</div>
<div class="col-md-6">
<h2>Content</h2>
<p class="description">asd</p>
</div>
</div>
Note: in the example above, all images are placed at the top of the parent by default. If you want some images to start at a different location, then give it a top property. In the example below, I gave the third image a top=50px property to align it with the bottom of the second image:
.object-left {
position: absolute;
top: 0;
}
.main-image {
position: absolute;
left: 50px;
top: 0;
}
.object-right {
position: absolute;
left: 100px;
top: 50px;
}
.image {
height: 100px;
}
<div class="container-fluid">
<div class="col-md-4 image">
<img class="object-left" src="http://placehold.it/50x50" />
<img class="main-image" src="http://placehold.it/50x100" />
<img class="object-right" src="http://placehold.it/50x50" />
</div>
<div class="col-md-6">
<h2>Content</h2>
<p class="description">asd</p>
</div>
</div>
I think this is what you want to do. I would remove the inline style on the object- images and put that in the css. I left the top, left, right on .object- empty so that you can put where you want to place them.
Does this make sense?
.image {
position: relative;
}
.object-left {
position: absolute;
top: ;
left: ;
}
.main-image {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.object-right {
position: absolute;
top: ;
right: ;
}
<div class="image">
<div class="object-left"></div>
<div class="main-image"></div>
<div class="object-right"></div>
</div>
Related
Below is my code, my goal is to prevent the div with an id "description" to overlap on the div with class name "container_display". How can I achieve this? I want the second div to show at the bottom of the image.
#container_display {
position: relative;
}
#container_display img {
position: absolute;
top: 0;
left: 0;
}
<div id="container_display">
<img src="image1.png" />
<img src="image2.png" />
</div>
<div id="description">TEXT HERE</div>
You need to set a height for the container, because the absolutely positioned elements are not considered to occupy width or height in the container.
Details on MDN:
absolute
The element is removed from the normal document flow, and no space is created for the element in the page layout
#container_display {
position: relative;
height: 60px;
}
#container_display img {
position: absolute;
top: 0;
left: 0;
height: 60px;
}
<div id="container_display">
<img src="https://i.ibb.co/KzWG55K/Pokemon-PNG-Image.png" />
<img src="https://i.ibb.co/x8r33KL/Pokemon-Free-Download-PNG-1.png" />
</div>
<div id="description">TEXT HERE</div>
There is one way to "hack it", which is to place one static image there and make it visibility: hidden, which is to occupy space, but not visible, and the position back to static:
#container_display {
position: relative;
}
#container_display img {
position: absolute;
top: 0;
left: 0;
height: 60px;
}
#container_display .spacer {
visibility: hidden;
position: static;
}
<div id="container_display">
<img src="https://i.ibb.co/KzWG55K/Pokemon-PNG-Image.png" />
<img src="https://i.ibb.co/x8r33KL/Pokemon-Free-Download-PNG-1.png" />
<img class="spacer" src="https://i.ibb.co/x8r33KL/Pokemon-Free-Download-PNG-1.png" />
</div>
<div id="description">TEXT HERE</div>
You don't need this:
#container_display img {
position: absolute;
top: 0;
left: 0;
}
You could also add a break between both divs to create space between them, like this:
<div id="container_display">
<img src="image1.png" />
<img src="image2.png" />
</div>
<br>
<div id="description">TEXT HERE</div>
I realize this has probably been asked 10000 times at this point, but I can't for the life of me figure out why it isn't working for me...
As the title says, i have a "background" image that i want to place text/links on top of, below is my code:
CSS
.2020-main {
position: relative;
}
.2020-dg-cta {
position: absolute;
top: 100px;
left: 75px;
}
HTML
<div class="2020-main">
<img src="{{media url="wysiwyg/media/newfor2020/main-bg.jpg"}}" alt="" />
<div class="2020-dg-cta">
<div class="2020-cta-brand">Dreamgirl</div>
<div class="2020-cta-name">Main Collection</div>
<div class="2020-cta-button"><a href="" >Shop Collection</div>
</div>
</div>
From my understanding, you give the containing div (2020-main) position: relative; and the child div (2020-dg-cta) position: absolute;, but this doesn't seem to work for me. .2020-main appears below the image, as it usually would without styling.
Any help would be highly appreciated
Thank you
CSS identifiers cannot start with a number. try renaming your classes like this
.main {
position: relative;
}
.dg-cta {
position: absolute;
top: 100px;
left: 75px;
}
<div class="main">
<img src="{{media url=" wysiwyg/media/newfor2020/main-bg.jpg "}}" alt="" />
<div class="dg-cta">
<div class="cta-brand">Dreamgirl</div>
<div class="cta-name">Main Collection</div>
<div class="cta-button">View Catalogue</div>
<div class="cta-button">Shop Collection</div>
</div>
</div>
You can use classes starting with numbers but you need to put the first number like this in the .css. Check this for more info.
.\32 020-main {
position: relative;
}
.\32 020-dg-cta {
position: absolute;
top: 100px;
left: 75px;
}
<div class="2020-main">
<img src="https://picsum.photos/200/300" alt="" />
<div class="2020-dg-cta">
<div class="2020-cta-brand">Dreamgirl</div>
<div class="2020-cta-name">Main Collection</div>
<div class="2020-cta-button"><a href="" >Shop Collection</div>
</div>
</div>
I want to display one image over another. It have to be responsive, with cutting image's edges if i resize. (see the pictures. i can't directly embedded images yet, without 10 reputation). How can i do that?
Here's the code:
<div class="content">
<div class="content-item_1">
<img class="img1" src="photo/image1.png" />
text1. text text
</div>
<div class="content-item_2">
<img class="img2" src="photo/image1.png" />
text2. text text
</div>
</div>
Something like this https://jsfiddle.net/5woswyxc/2/
but image 2 have to be slighty over image 1, if it resize.
and when size is reduced - text 1 must move on the top on image 2.
(image1 is moved to bottom)
resized layout
try this:
<body>
<div class="content">
<div class="parent">
<img class="image1" src="http://openclipart.org/image/300px/svg_to_png/4112/Clue_Simple_Clouds.png" />
<img class="image2" src="http://openclipart.org/image/300px/svg_to_png/4112/Clue_Simple_Clouds.png" />
</div>
</div>
<style>
.parent {
position: relative;
top: 0;
left: 0;
background-color: blue;
width: 450px;
height: 320px;
overflow: hidden;
}
.image1 {
position: relative;
top: 0;
left: 0;
}
.image2 {
position: absolute;
top: 30px;
left: 70px;
}
</style>
</body>
I've successfully displayed an image over another image like this:
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12">
<div class="image-with-overlay">
<div class="shop-now-overlay">
<img src="img/btn_shop_now.png">
</div>
<img src="img/left_image.jpg"/>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
<div class="image-with-overlay">
<div class="shop-now-overlay">
<img src="img/btn_shop_now.png">
</div>
<img src="img/right_image.jpg"/>
</div>
</div>
</div>
And this is how my stylesheet looks like:
.image-with-overlay {
position: relative;
}
.image-with-overlay .shop-now-overlay {
position: absolute;
z-index: 10;
bottom: 0;
right: 0;
padding-bottom: 30px;
padding-right: 30px;
}
But I want my page to be responsive and of course, everytime I resize my browser smaller and the images gets displayed on a single column (col-sm-12), the overlay button displays outside the image and takes the width of the page.
Any ideas on how I can restrict the image overlay to only wrap around the image even when the screen is smaller?
Looks like the responsive.css makes it static! Can you try with !important? I won't recommend this but checking doesn't hurt.
.image-with-overlay {
position: relative !important;
.shop-now-overlay {
position: absolute !important;
z-index: 10;
bottom: 0;
right: 0;
padding-bottom: 30px;
padding-right: 30px;
}
}
Try removing the padding element and try to handle the position with left and right : 30px
.shop-now-overlay {
position: absolute;
z-index: 10;
bottom: 0;
right: 0;
}
I want to fix an image above the slider, I've used the below code. It gets fixed but the problem is that, if I minimize or resize the browser, the image moves from that position and takes its own place.
CSS:
.imageover{
background:transparent;
bottom: 0;
color: #FFFFFF;
left: 0;
position: absolute;
width: 100%;
z-index: 8;
opacity:1.0!important
}
HTML:
<div class="topbanner" width=1000px>
<div class ="imageover">
<img src="images/greendesign.png" width =350/>
</div>
<div id="sliderFrame">
<div id="slider">
<img src="images/slider1.png"/>
<img src="images/slider2.jpg" />
<img src="images/slider3.jpg" />
<img src="images/slider4.jpg" />
<img src="images/slider5.jpg" />
<img src="images/slider6.jpg" />
</div>
</div>
</div>
Use position: fixed; if this an image that you want fixed on a place on the page, and unaffected by scrolling.
.imageover{
background: none;
bottom: 0;
color: #FFFFFF;
left: 0;
position: fixed;
width: 100%;
z-index: 8;
opacity: 1.0 !important
}
More on the position property here.