How To Overlay One Div Over Another - W3docs
Maybe your like
- Password Generator
- HTML Editor
- HTML Encoder
- Base 64
- Code Diff
- JSON Beautifier
- CSS Beautifier
- Markdown Convertor
- Find the Closest Tailwind CSS Color
- Phrase encrypt / decrypt
- Browser Feature Detection
- Number convertor
- JTW Decoder
- CSS Maker
- CSS Maker text shadow
- CSS Maker Text Rotation
- CSS Maker Out Line
- CSS Maker RGB Shadow
- CSS Maker Transform
- CSS Maker Font Face
- Color Picker
- Colors CMYK
- Colors HWB
- Colors HSL
- Color Hex
- Color mixer
- Color Converter
- Colors RGB
- Color Contrast Analyzer
- Color Gradient
- String Length Calculator
- MD5 Hash Generator
- Sha256 Hash Generator
- String Reverse
- URL Encoder
- URL Decoder
- Base 64 Encoder
- Base 64 Decoder
- Extra Spaces Remover
- String to Lowercase
- String to Uppercase
- Word Count Calculator
- Empty Lines Remover
- HTML Tags Remover
- Binary to Hex
- Hex to Binary
- Rot13 Transform on a String
- String to Binary
- Duplicate Lines Remover
- Dark
- Light
- System
- Books
- Learn HTML
- Learn CSS
- Learn Git
- Learn Javascript
- Learn PHP
- Learn python
- Learn Java
- How To
- How To NodeJs
- How To Linux
- How To AngularJs
- How To PHP
- How To HTML
- How To CSS
- How To Symfony
- How To Git
- How To Apache
- How To JavaScript
- How To Java
- How To Vue.js
- How To Python
- Snippets
- HTML
- How to Overlay One Div Over Another
Creating an overlay effect for two <div> elements can be easily done with CSS. This can be done with the combination of the CSS position and z-index properties. The z-index of an element defines its order inside a stacking context. In our examples, we’ll use the “absolute” and “relative” values of the position property and add the z-index property to specify the stacking order for the positioned elements.
So, let’s start!
Create HTML
- Use a <div> element with the class named “container”.
- Add two other <div> elements within the first one. Add classes to them as well.
Add CSS
- Specify the width and height of the "container" class. Set the position to "relative" and add the margin property.
- Set both the width and height of the "box" class to "100%". Specify the position with the "absolute" value. Add the top and left properties. Also, specify the background and opacity of the "box" class.
- Style the "overlay" class by using the z-index, margin and background properties.
Now, we can bring together the parts of our code.
Example of overlaying one <div> over another:
<!DOCTYPE html> <html> <head> <title>Title of the document</title> <style> .container { width: 150px; height: 150px; position: relative; margin: 30px; } .box { width: 100%; height: 100%; position: absolute; top: 0; left: 0; opacity: 0.7; background: #0057e3; } .overlay { z-index: 9; margin: 30px; background: #009938; } </style> </head> <body> <div class="container"> <div class="box"></div> <div class="box overlay"></div> </div> </body> </html> Try it Yourself »Result
Let’s see another example where we use a bit more CSS. Here, we add some hovering effects using the CSS :hover pseudo-class.
Example of overlaying one <div> over another with hovering effects:
<!DOCTYPE html> <html> <head> <title>Title of the document</title> <style> .container { position: absolute; height: 250px; width: 400px; background-color: #7d807e; } .box1 { color: #fff; padding-top: 60px; padding-left: 50px; font-size: 50px; font-weight: bold; } .box2 { padding-left: 50px; } .box1:hover { z-index: -1; opacity: 0.5; font-size: 30px; text-align: center; transform-style: all; transition-duration: 2s; } .box2:hover { z-index: -1; opacity: 0.3; font-size: 40px; text-align: center; transform-style: all; transition-duration: 2s; } </style> </head> <body> <div class="container"> <div class="box1">W3Docs</div> <div class="box2">Learn programming</div> </div> </body> </html> Try it Yourself » Tags html css div overlay positionRelated Resources
- How to Horizontally Center a <div> in Another <div>
- How to Make an HTML <div> Element not Larger Than its Content
- How to Align the Content of a Div Element to the Bottom
- How to Horizontally Center a Div with CSS
- How to Vertically Center a <div>
- How to Vertically Align Elements in a Div
- How to Center a Button Both Horizontally and Vertically within a Div
- PHP basics
- HTML Basics
- Javascript Basics
- CSS Basics
- ES6 Basics
- TypeScript Basics
- React Basics
- Angular Basics
- Sass Basics
- Git Basics
- Vue.js Basics
- SQL Basics
- Python Basics
- Java Basics
- NodeJS Basics
Tag » How To Overlay Two Divs
-
How To Overlay One Div Over Another Div - Html - Stack Overflow
-
How To Overlay One DIV Over Another DIV Using CSS
-
How To Overlay One Div Over Another Div Using CSS - GeeksforGeeks
-
How To Create An Overlay Effect - W3Schools
-
How To Overlay Two Divs With CSS (CSS GRID). - YouTube
-
How To Overlay One DIV Over Another DIV Using CSS? - Studytonight
-
How To Stack Elements In CSS
-
Overlay Two Div's Problem : R/css - Reddit
-
How To Make Div Overlay Another Code Example
-
CSS Overlay - Javatpoint
-
How To Make An Overlay Between Two Div In Css Code Example
-
How Can I Overlay Two Divs So That The Container Div Fits Them Both
-
How To Overlay One Div Over Another Div - Technomark.In
-
How To Overlay Divs Without Absolute Positioning It.