Skip to content
Advertisement

How to put div over image with HTML and CSS?

I’m still a beginner in programming and I’m doing a project to improve knowledge.

I need to insert a div with text on top of an image, I’m trying to recreate the example of the image below:

enter image description here

Half of the div is an image and the other half is text. Can you tell me how I can do that?

Here’s my code I put into codesandbox

JavaScript

Thank you in advance.

Advertisement

Answer

You have two solutions to set a background image :

use the background properties in CSS

JavaScript

use positioning to make a custom layout

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement