Overlaying text on several images

My challenge is centering text over multiple images using a combination of Bootstrap and CSS. While most online resources suggest using position: absolute; to achieve this, I have only been successful in centering the text in the middle of the screen rather than directly over the image. I suspect that Bootstrap may be causing some interference.

I aim to have the text on top of the images with animation effects like fading in as the user interacts with them.

Although I've researched extensively on this topic, most tutorials and articles focus on achieving this effect with a single image. Attempting to apply similar techniques to multiple images seems to require a different strategy altogether.

In an effort to troubleshoot, here is the relevant snippet of code:

      
      .imgText {
        position: absolute;
        z-index: -1;
      }
      
      .imgList {
        z-index: -2;
      }
    <div class="row justify-content-center mt-3">
      <div class="ml-4 imgList">
        <img src="https://via.placeholder.com/200x200">
        <div class="imgText justify-content-center m-auto">
          test text
        </div>
      </div>
      <div class="ml-4 imgList">
        <img src="https://via.placeholder.com/200x200">
        <div class="imgText justify-content-center m-auto">
          test text
        </div>
      </div>
    </div>

You can view the live results here.

Answer №1

Thank you for checking this out!

JSFiddle Example

To achieve the desired effect, make sure to designate the parent element with position: relative so that it serves as a reference point for the absolutely positioned element (in this case, the text).

Here is the CSS code snippet to center the element both horizontally and vertically:

top: 50%; left: 50%; transform: translate(-50%, -50%)

Additionally, don't forget to include a z-index property to ensure the text appears above the image.

.ml-4 {
    position: relative;
}

.imgText.m-auto {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
}
<!doctype html>

<!-- HTML sample content here -->

</body>
</html>

Answer №2

give this a shot

.imageText {
    position: relative;
    transform:translate(-50%,-50%);
     top:50%;
    left:50%;
    z-index: 22;
  }

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

Customize Angular Material styles uniquely across various components

Within my application, I am utilizing two components that contain tab groups. The first component serves as the main page, where I have adjusted the CSS to enlarge the labels by using ViewEncapsulation.None. The second component is a dialog, and I aim to m ...

How to effectively utilize `MutationObserver` for monitoring the properties of an `HTMLElement` instead of focusing on its attributes

By using the MutationObserver.observe() method, I am able to monitor changes in a specific attribute. For instance, if I have a Div element and the attribute value is modified, then the designated callback function will be executed. However, if the propert ...

Is there a way to insert an attribute in HTML without simply appending it to the end of the tag?

I've been working on incorporating the code snippet below that I found in an angularjs table sort function. In the code, you can see the ts attributes being added to the html. However, this method is not suitable for hosting on Salesforce. Can anyone ...

Animating CSS styles in Vue.js based on JavaScript triggers

Within my Vue.js application, I've implemented a login form that I'd like to shake whenever a login attempt fails. Though I have achieved the desired shaking effect, I'm not completely satisfied with my current solution. Here's a simpl ...

Despite utilizing the here() package, Pandoc is unable to locate the image path referenced in an external HTML file that has been imported into R Markdown

As I create an HTML document with R Markdown, I incorporate external HTML documents for headers and footers. Utilizing the here() package enables relative paths within my project. However, including external HTML files via YAML in the R code disrupts the f ...

Is storing text in data-content and utilizing bootstrap-popover.js compatible?

Is it possible to display HTML content in a popover using ? How reliable is it to store text in data-content? Can we expect it to function properly across all browsers? ...

I desire to share the JSON information and receive the corresponding response data

<!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> </head> ...

Adding a logo to a website that utilizes CSS, HTML, JS, and Bootstrap

Hey there! I'm new to the world of Front-end development and I've been learning by watching videos and reading everything I can find on the Internet. Currently, I'm using HTML, CSS, and JS for my website. Can anyone help me figure out how to ...

Is it possible to use WHILE loops twice in PHP?

Just starting out with PHP and hoping for some assistance. I have a MySQL database table with columns for "id", "img", "link", and "desc". My goal is to echo all of this data in the following format: <div id="featured"> <a target='_b ...

What is the best way to incorporate width adjustments in an image source for a responsive website?

Currently learning CSS and experimenting with it on an HTML page. For reference, I'm using this link. Encountering an issue with a responsive header image that adjusts size based on device (small on mobile, large on desktop). Is it possible to achiev ...

"Implementing JQuery addClass Functionality to Enhance Menu Sty

I've created a menu that is stacked on top, with the "Representaciones" section shown on the same page below a welcome image. However, when I click on it, everything works fine but if I refresh the page, the "selected" class disappears from "represent ...

What methods are available for modifying nodes generated dynamically?

I have been on a quest for quite some time now to find a way to manipulate HTML content that has been dynamically added. Initially, I fetch a cross-domain website using getJSON: $.getJSON('http://whateverorigin.org/get?url=' + encodeURIComponent ...

Guide to creating a responsive layout using CSS and HTML

I am looking to position the main contents (content 1 and content 2) in between two side menus on my exercise page. At the moment, the main contents are overlapping with the two menus. Can someone guide me on how to fix this alignment issue? Thank you. ...

Create waypoints on multiple elements

I am working on implementing a unique feature using a div tag with the class "dipper." <div class = "dipper"> <p>Peekaboo</p> </div> As part of this implementation, I have included a script that triggers the display of the "dipper ...

Generating dynamic anchor tags in Vue.JS

I have a JavaScript object that I want to convert into HTML elements and display it in Vue.js. So far, my approach has been to convert the object into strings representing HTML elements and then add them to the template. However, even though this method di ...

Extract Information from a Website

Is there a way to extract data from another website using JavaScript and save it into a .TXT or possibly an XML file? If JavaScript is not the best solution, I am open to other suggestions. I am specifically interested in extracting the price and item na ...

Leveraging an HTML form for searching and fetching data from MySQL Workbench using PHP

I'm currently working on fetching data from my database by utilizing an HTML form and establishing a PHP connection to my SQL workbench. The data retrieval is successful, as it appears at the top of my webpage. However, I am facing issues with executi ...

Hover over a row in one table to modify the appearance of another row in a different table

Is there a way to change the appearance of rows in one table when hovering over rows in another table that are related? You can find a JSFiddle link illustrating what I am trying to achieve. Here is an example of the code: table#table1 #el1:hover + ta ...

Tips for aligning a menu that expands from the side to the center

I'm trying to center the menu on my webpage, but the issue is that it's stretching from the sides. Here's a sample image of the menu layout: I'm struggling to figure out how to fill the empty space on the left side of the menu. ...

The Page Transcends the Boundaries of the HTML Tag

This particular issue sets itself apart from the common overflow problems that are often faced by people. Interestingly, I have only encountered this problem while using Chrome (Version 41.0.2272.101 64-bit). IE 9+ and Firefox, on the other hand, seem to b ...