Using Div in Bootstrap to Overlay Text on an Image

Trying to overlay text on an image using the code snippet below;

https://i.sstatic.net/7jkEC.png

<div class="wrapper">
<img src="https://cdn0.vox-   cdn.com/thumbor/qLH7593e3D2SSSIdkwgBWdYhjjk=/289x0:802x684/400x533/filters:forma t(webp)/cdn0.vox-cdn.com/uploads/chorus_image/image/47859707/6621139883_e6be6a217a_b__1_.0.0.jpg"  alt="" />
 <div class="overlay">
    <h2>Restaurant Stowaway Devours $800 of Roast Goose and Wine</h2>

 </div>
 </div>

CSS

body {
  text-align: center;
}

.wrapper {
    display: inline-block;
    margin-top: 25px;
    position: relative;  
}

.wrapper img {
   display: block;
   max-width:100%;
}

.wrapper .overlay {
    position: absolute;
    top:0;
    left:0;
    width:100%;
    height:100%;
    background-color: rgba(0,0,0,0.25);
    color:white;
}

However, the result appears different from what was expected as shown in this image: https://i.sstatic.net/zAi5J.png

I could use some assistance in identifying what I have overlooked, as I aim to achieve the desired output similar to the initial image displayed above.

Answer №1

To modify the appearance of your header h2 tag, you need to assign a class to it and then apply the following styling rules. Use the designated class as shown below,

 <h2 class="custom-header">New Recipe: How to Bake the Perfect Apple Pie</h2>

h2.custom-header {
    top: 0;
    position: relative;
    text-align: center;
    width: 100%;
}

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

Is there a way to identify if the parent page has completed loading while within an iframe?

Is there a way to detect properties or events within the iframe that can help determine this? The src of the iframe and the parent page belong to different domains. ...

Having trouble accessing the div element inserted by the Angular application

I've encountered an issue while trying to access a div that is injected into the DOM by an Angular app on the page. Below is the script I have placed at the end of the HTML page: $(document).ready(function () { var targetNode = document.querySelect ...

Exploring Javascript parameters with the power of jquery

Is it possible to pass a parameter from PHP into a JavaScript function within HTML? I am currently facing an issue where my code crashes when it reaches a certain condition. This is the code snippet causing the problem: $str="<input type='submit&a ...

Issue with radio button functionality in email communication

I'm experiencing an issue with a form that contains 2 sets of radio buttons. The first set has 5 options, while the second set has 2 options. The form functions correctly, but upon submission, the email only displays the first option selected instead ...

Guide on attaching an event to every dynamically created element in JavaScript

I'm currently generating 'li' elements dynamically using a loop and running into issues when it comes to assigning events to each generated element. My goal is to assign an onclick event to every li element that is created. Check out the co ...

CSS or jQuery: Which is Better for Hiding/Showing a Div Within Another Div?

Show only class-A at the top of the page while hiding all other classes (x,x,c). Hide only class-A while showing all other classes (x,x,c). Is it possible to achieve this? <div class="x"> <div class="y"> <div class="z"&g ...

Steps to showcase an image from MongoDB in HTML using Java with Spring Boot

My current task involves displaying an image based on the unique identifier obtained from the FindById() method. I have successfully retrieved the image data from MongoDB through a Rest Call, but now I need to show this image to the user in a web browser u ...

Request Fancybox from parent document within an iframe

I have two pages, my index.html and social.html. I recently cleaned up my index.html file and left only the necessary jQuery code for using fancybox. My goal is to display images from social.html within fancybox when clicked on, but it should open in index ...

Prevent scrolling with absolute positioning

Here's a snippet of my HTML pseudocode: <div> <VideoAnimation /> <div className="under-animation"> // a lot of content goes here </div> </div> The issue arises from using absolute positioning on th ...

Ensure that Roboto font is utilized on IE 11 and Edge browsers

My goal is to implement the Google Roboto font in my project, but I'm noticing that it doesn't display properly in IE11 / Edge browsers. Below is a snippet of my code: <!DOCTYPE html> <html> <head lang="en"> <meta charse ...

Pop-up window for uploading files

Looking for assistance with my file uploading system. I am utilizing a unique purple button from http://tympanus.net/Development/CreativeButtons/ (Scroll down to find the purple buttons). Additionally, I am using a wide, short content popup feature availa ...

How to implement div scrolling on button click using Angular 4

Is there a way to make the contents of a div scroll to the left when one button is clicked and to the right when another button is clicked? I've tried using ScrollLeft, but it doesn't seem to be working... Here's the HTML code: <button ...

The appearance of the website varies across different web browsers

My current project involves creating a portfolio showcasing my work, but I've encountered an issue: When you visit my website and click on the "About" link, the text at the bottom of the tab is displayed differently in Chrome compared to IE and Firef ...

The touchend event and target _blank are not working together harmoniously

With both image and link hover states in place, I've implemented a piece of code to ensure that opening a link on iOS only requires a single tap. Check out the code below. However, I've encountered an issue where using a link with target="_blank ...

Create a video player in your HTML code using the class "afterglow", and also link a separate class to it for additional styling

I'm encountering some challenges with a project that involves a JS file for a Bootstrap modal popup and an HTML5 video player. The issue I'm facing is that I am unable to link the class for the video player theme. Can anyone here assist me in ide ...

What is the best way to create a horizontal scrolling feature for a two-row layout using Bootstrap?

When using one row, the script works successfully. Here is an example of the code: html : <div class="testimonial-group"> <div class="row"> <div class="col-md-4">1</div> <div class="col-md-4">2</div> < ...

The range input in HTML does not respond when attempting to adjust it

I am having an issue where the thumb on the slider does not move when I try to. This problem occurred after I inserted an img element inside the slider-cntnr div. View the code at http://codepen.io/danielyaa5/pen/xVEXvB HTML <div id="slider-cntnr"&g ...

How do you implement radio button logic within an *ngFor loop?

When I populate options in a form with radio buttons, I am not seeing isChecked set to true when I select an option. Am I missing something in the following Angular code? app.component.html <div class="form-group"> <label>answerOption</la ...

Disabling the @import cache feature in LessCSS Assetic

I'm facing a minor issue that is robbing me of precious time. Currently, I am using the assetic plugin with the lesscss filter in my symfony2.1 project. The problem lies in Assetic not detecting changes in imported files when using the @import functi ...

Placing Bootstrap nav-items outside of the justify-content-center alignment

Having trouble positioning a button in the nav container to the right side of the screen while keeping all other nav items centered using justify content center. I've tried the following solutions: Using margin-left:auto on the button, but it shifts ...