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 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
Overview of Drupal and how it worksDrupalHow to remove trailing characters from a string using JavaScript?JavaScriptKilling A Project Part 1: What criteria should be used to cancel/kill a project?MiscellaneousOptional arguments, Default parameters and REST parameters in JavaScriptJavaScriptHow to make a curtain slider using jQuery and CSS?CSSHow to Use SQL MAX() Function with Dates?SQL/MySQLAdvanced Array Methods in JavaScript (with examples)JavaScriptHow to change style of all direct children of an element using jQuery?jQueryHow to display a student’s individual transcript in Colleague?ColleagueLearn to Establish Connection using MySQLi (object-oriented), MySQLi (procedural) and PDO with Example CodePHPPostgreSQL transactions using the BEGIN, COMMIT, and ROLLBACK statements.PostgresWhat are Identifiers in JavaScript?JavaScript