All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

Background Image Overlay CSS

Last Updated : Mar 11, 2024

Background Image Overlay CSS

In this tutorial we will show you the solution of background image overlay CSS and how to create an overlay of background image using CSS. Here, overlay of background image means that an image is set to the background with and without text.

This is the whole concept. We can use this concept of overlay in many ways like in some events and by default also.

Step By Step Guide On Background Image Overlay CSS :-

Now, we are going to understand the CSS image scale to fit with the help of the object-fit CSS property.

The object-fit property in CSS has some values, let us take a look at them.

  • Fill: with help of this property, the image will be resized according to the required dimensions, this fill is the default value of the object-fill property.
  • None: none is used where we do not want to resize the image.
  • Cover: The image will be clipped to fit with help of this value.
  • Contain: using this the image keeps its aspect ratio but is resized to fit within the given element.
  • Scale-down: using this the image is scaled downed to its lowest version.
<!DOCTYPE html>
<html>
<head>
<title>
Background image overlay CSS
</title>
<style>
#main {
 background: url("sample_image.jpg") no-repeat fixed;
 height: 100vh;
 overflow: hidden;
 background-color: rgba(07, 11, 02, 0.5);
 background-blend-mode: soft-light;
}
</style>
</head>
<body id="main">
<h1> TalkersCode - CSS Tutorials </h1>
<h2> Background image overlay CSS</h2>
</body>
</html>
  1. As, here we see that we that in above example we show you an example in which HTML and CSS codes are used.
  2. Here, first of all, we create a basic structure of HTML, in which we use <!DOCTYPE html> which defines the type of document. And next one is our HTML tags. These tags are paired tags and all the data regarding HTML is written inside these tags.
  3. After we use our head tag which is again paired tag and contains the title and meta information of the webpage. The data written inside the head is not shown on the webpage.
  4. Now, next is our title tag which defines the title of the webpage. The tag which has its closing tag is known as a paired tag. So, this is again a paired tag.
  5. Now, next is the body which is the main tag of HTML. The data which we have written inside the body is shown on the webpage. Mostly all tags which are helpful to show data or information on the screen are written under the body tag.
  6. Now, as above we see that to use an overlay of the image as background, we give a class to the body. We can also apply this to the div and another HTML tag.
  7. After that we give style to id or class which we use on the HTML component. And here we directly use background-URL to apply image and many other CSS properties which help to create an overlay effect.

Conclusion :-

At last, in conclusion, here we can say that with the help of this article we can understand background image overlay CSS.

I hope this tutorial on background image overlay CSS helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Pragati

Experienced coding content writer who enjoys breaking down complex concepts in programming languages like Java, Python, C, and C++. Over three years of experience producing interesting and relevant content for a variety of entities. Committed to providing concise and easy-to-understand articles that assist readers in easily understanding technology and industry trends in the world of coding and software development.

Follow Pragati On Linkedin 🡪