Steps to Make a White Content Box on Top of an Image Background using HTML/CSS

I am currently struggling with overlaying a white box on top of my background image in order to have my text inside the box for a more visually appealing look. Despite trying to add CSS code like this:

.white-box {
    position: absolute;
    background-color: #FFFFFF;
    color: black;
    width: 50px;
    height: 50px;
    padding: 20px;
}

and inserting HTML tags like this:

<body>
<div class="white-box">
Content
</div>
</body>

I have not been successful in achieving the desired effect on my webpage. My online search results only show variations of what I have already attempted (as shown above). You can see the look I am aiming for here.

Any assistance or guidance would be greatly appreciated! :)

Answer №1

Take a look at this code snippet. When placing an image within a parent element (like in the example where div.image is the parent of div.content), there is no need to use position: absolute.

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

.image {
  min-height: 100vh;
  background-image: url(https://miro.medium.com/max/1200/1*mk1-6aYaf_Bes1E3Imhc0A.jpeg);
  background-size: cover;
  background-repeat: no-repeat;
  padding: 30px;
}

.content {
  background: white;
  padding: 15px;
  border-radius: 3px;
}
<div class="image">
  <div class="content">
    <h1>What is Lorem Ipsum?</h1>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
    survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
    software like Aldus PageMaker including versions of Lorem Ipsum.
  </div>
</div>

If you want to display the image on the document body directly, you can simply add the image class to the <body> tag instead of creating a separate container div.

Answer №2

Take some time to carefully examine the website and the CSS that it is utilizing. This can provide you with valuable insights and help enhance your skills (:

One effective strategy could be to apply a background image to the outer div, set the overflow to scroll, and then create a nested div within it with a white background, similar to what is demonstrated on the website.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What causes the variation in default margin between React and traditional HTML?

There seems to be a difference in margin between <button> elements when rendered by React compared to plain HTML. Plain HTML adds a small margin between the buttons, while React removes it completely. Does anyone have an explanation for this discrep ...

The $.post method is malfunctioning

I am experiencing an issue where the onchange function is working properly, but the $.post function is not functioning as expected. Below is the HTML code snippet: <input type="checkbox" id="chk" value="3" onchange="checkradio(this.value)"/> Here ...

The layout of the table is not formatted in a single continuous line

I recently implemented the material-ui table and noticed that the header has a multiline break space. I am looking for a way to make it display in a single line instead. Is there any solution for achieving this using material UI or CSS? Feel free to chec ...

Centering an icon vertically and introducing animation upon hovering over an image

I'm having difficulty with vertically centering an icon that drops down on image hover, and I want to make its transition smoother. Currently, it's dropping down too abruptly and no matter what transition property I apply (ease, ease-out, etc.), ...

Leverage HTML within JSON for a multilingual website using i18next with Next.js

I am working on a multi-language website using Next.js. To handle the translations, I am using the package i18next. In my JSX code, I define variables like this: {t("satisfied:title")} This means {t("JSONfileName:JSONvariable")} However, when I try to i ...

Is there a way to eliminate unknown white gaps in the content?

I have encountered a very perplexing issue. When accessing this site on Safari, an additional 4-500px of scrollable whitespace is added. This is clearly not the intended behavior, but I am struggling to understand what is causing this space :S Upon inspe ...

Increase the identification of HTML element with jQuery

I've encountered an issue while trying to increment the id of 2 HTML elements, hwAddition and itemNumber, upon a button click event. The HTML code in question is as follows: <div id="hwAddition"> <div id="itemNumber" s ...

What circumstances could lead to Chrome's autofill feature ceasing to function?

Currently, we are in the process of developing a new website that utilizes HTML5. While everything validates correctly, we are encountering issues with the LESS stylesheets and Facebook tags. Particularly, Chrome's autofill feature is not functioning ...

What is the correct method for handling images in HTML and CSS?

Hey there! Just playing around on jsfiddle and wanted to share this Destiny-inspired creation: http://jsfiddle.net/3mfnckuv/3/ If you're familiar with Destiny, you'll see the inspiration haha.. But here are a few questions for you: 1) Any ide ...

Tips on optimizing a setTimeout script for seamless integration with an HTML form

Here is the script: <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script> function addToCart() { document.getElementById("msgs-box").innerHTML = "Item added to cart s ...

Footer not sticking to bottom using bootstrap version 5.2.2

I am currently working on a project using Laravel Inertia Vue and bootstrap 5.2.2 as part of my dependencies. After loading the css to the tag, I attempted to create a sticky footer. However, I found that the footer is not sticking to the bottom as expect ...

Unable to execute project using CodeIgniter

I'm facing an issue with my current project. Unfortunately, I can't share the website due to confidentiality reasons. I apologize for any inconvenience this may cause. The project is built on the CodeIgniter framework, and it runs smoothly on lo ...

Update the scrollspy navigation in a div with overflow by toggling the active class

Struggling to implement a navigation menu within a self-scrolling div using html/css/jquery. Looking for the menu items to toggle the active class when in view or at the top of the scrolling div. I'm essentially trying to achieve something like this ...

Show detailed information in a pop-up window

Javascript $(function() { var dmJSON = "clues.json"; $.getJSON( dmJSON, function(data) { var idx=1; $.each(data.details, function(i, f) { var myid = 'mypop'+String(idx); idx++; var $popup="<popu ...

How can I adjust the gravity or positioning of a tipsy tooltip in jQuery?

Is there a way to adjust the position or gravity of Tipsy? The plugin offers various options for gravity that can be set through the script: nw | n | ne | w | e | sw | s | se Currently, I have set it to s position, as shown in this demo: http://jsfiddle. ...

What is the best way to showcase my products in a horizontal line? I am seeking a solution using PHP and Bootstrap to exhibit all the items retrieved

I am experiencing an issue with displaying the most recent events from my database using PHP. The Bootstrap framework and CSS are causing them to appear as a single column on the page, but I would like them to be displayed in rows of three. I have attempt ...

Verify image loading using jQuery

<img src="newimage.jpg" alt="thumbnail" /> I am dynamically updating the src attribute of this image. Is there a way to verify if the image has been successfully loaded and take action once it is? Appreciate any guidance on this matter. ...

Run javascript code after the page has transitioned

Struggling to create a dynamic phonegap app with jQuery Mobile, the issue arises when loading JavaScript on transition to a new page. The structure of my index page is as follows: <body> <div data-role="page" id="homePage"> <div data- ...

JavaScript can dynamically attach EventListeners to elements, allowing for versatile and customized event

I am currently populating a table using data from an XML file. One of the columns in the table contains links to more details. Due to the unique requirements of my web page setup (Chrome extension), I need to dynamically add an event handler when the table ...

Making <div> elements responsive by rearranging their display order using CSS in media queries, troubleshooting issues with floats, and adjusting font sizes

I'm currently working on a webpage located at: On this page, there is a containing division with 5 elements inside. They are floated left in order to align vertically, but I am facing some challenges when it comes to adjusting my CSS for media querie ...