Yogesh Chauhan's Blog

How to position an image on top of another image using CSS?

in CSS on August 8, 2020

Solution 1

HTML


<img src="" class="image_1">
<img src="" class="image_2">

CSS


img {
  position: absolute;
  top: 25px;
  left: 25px;
}
.image_1 {
  z-index: 1;
}
.image_2 {
  z-index: 2;
}

Solution 2

HTML


<div class="example">
  <img class="image_1" src="" />
  <img class="image_2" src="" />
</div>

CSS


.example {
  position: relative;
  top: 0;
  left: 0;
}
.image_1 {
  position: relative;
  top: 0;
  left: 0;
  border: 1px red solid;
}
.image_2 {
  position: absolute;
  top: 30px;
  left: 30px;
  border: 1px green solid;
}

Solution 3

HTML


<div class="container">
    <img src="" alt="">
    <img class="child" src="" alt="">
<div>

CSS


.container {
  border: 0;
  float: left;
  position: relative;
} 
.child {
  border: 0;
  position: absolute;
  top: 0;
  right: 0;
 } 

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Dec 4 What is Etrieve Flow? #Dec 2 The unique operator($) in Envision Basic #Nov 25 Steps to Install Microsoft SQL Server on a MacOS #Nov 11 What is DevOps? #Nov 10 The * arithmetic operator in Envision Basic #Nov 10 What are Big Data Clusters in SQL Server?
You might also like these
Few more :nth-child examples in CSSCSSWindow innerHeight and innerWidth properties in JavaScriptJavaScriptKeyValuePipe in Angular 9AngularWhat is Hoisting in JavaScript?JavaScriptWP_Query Class in WordPressWordPressHow to create rotating texts using JavaScript and CSS?CSSRBV Framework and closing of big brandsMiscellaneoususer_can vs current_user_can in WordPressWordPressHow to show and hide an element on click in React?ReactHow to pass arguments in SCSS function?SCSSHow to control file extensions with an .htaccess file?MiscellaneousPHP Login System using PDO Part 1: Create User Registration PagePHP