What is the best way to create a stylish table of images with text overlaid on each image using HTML and CSS?

Currently working on developing a website, and I am in the process of creating a panel consisting of images accompanied by text overlaid on each image. Initially, my approach involved using a <table>, but to my surprise, adding <p> tags resulted in the images stacking into one column rather than maintaining their table format.

Even experimenting with positioning the <p> elements as absolute did not yield the desired outcome.

I am seeking advice on how to successfully link each <p> element to the center of its corresponding image while preserving the original table layout. Any suggestions or insights are highly appreciated!

Answer №1

To utilize tables instead of divs, consider using the following code to center text over each image in every table cell:

<style>
.container {
  position: relative;
  text-align: center;
  color: white;
}

.centered {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
</style>
</head>
<body>

<table >
<td class="container">
  <img src="image.jpg" alt="" style="width:100%;">
  <div class="centered">Centered</div>
  </td>

  <td class="container">
  <img src="image.jpg" alt="" style="width:100%;">
  <div class="centered">Centered</div>
  </td>

    <td class="container">
  <img src="image.jpg" alt="" style="width:100%;">
  <div class="centered">Centered</div>
  </td>
</table>

</body>
</html> 

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 it considered a bad practice to apply overflow: auto to all elements with the exception of html?

My approach to beginning a new design always involves overriding the default padding and margin set by the browser on all elements: * { margin: 0; padding: 0; } After coming across j08691's response regarding a margin collapse issue, I discovered th ...

Steps for Deactivating HTML Links

I am facing an issue with a link button inside a <td> that needs to be disabled. It is working fine on Internet Explorer but not functioning properly in Firefox and Chrome. I have tried various methods, but nothing seems to work on Firefox (using ve ...

The page transition on Android lacks fluidity

Currently, I am working on developing a hybrid app with HTML5 and AngularJS. One of the features I have incorporated is the use of Angular animate for page transitions. However, I have noticed that while the transition is seamless on iOS devices, there s ...

How to change the video source on Internet Explorer

When setting the source of a <video> tag with JavaScript: $("#video-player").attr("src", '/DownloadCenter/GetFile?path=' + file.Path); Initially setting the source is not an issue, but using the same snippet multiple times results in the ...

A guide on sending JavaScript variables to PHP using AJAX

I've been facing an issue while trying to pass the selected month from a select list in HTML using Ajax. Every time I select a month, it doesn't show up as expected. Initially, there's a placeholder "nothing" displayed due to the if-else con ...

JavaScript - Reveal a div when a grid item is clicked

I have created a grid with a 5x7 layout using divs. I am trying to achieve a feature similar to the Netflix interface where, upon clicking on a div, a larger div will appear beneath it. This larger div should expand to 100% width of the parent container, p ...

Struggling to properly center my logo vertically

At my website, the logo in the top left corner is not centered. Here is the code I am using: .header_col1 { float: left; width: 20%; background: #009240; text-align: center; position: relative; } .header_col1 a { /* my logo */ d ...

Customizing Material UI - Overrides in MakeStyles

Hello there! I'm currently facing a challenge with adding custom CSS to a material UI App Bar. Despite using the makeStyles function, all of my styles are being overridden by the default Material UI styling. The only solution I have found so far is to ...

Navigate to a hyperlink using an HTML tag on an Android device

Hi there, I have an HTML string that includes a tag with a href attribute. After setting this HTML string in a text view on Android, I want only the tag with the href attribute to be clickable and redirect to the appropriate link. Can someone please advise ...

What is the best way to align a bootstrap 5 iframe in the center?

<div class="ratio ratio-4x3 justify-content-center align-items-center mx-auto"> <iframe src="https://www.facebook.com/plugins/page.php?href=https%3A%2F%2Fwww.facebook.com%2Fprofile.php%3Fid%3D100085514265694&tabs=timeline&width=500& ...

Excessive Bootstrap row reaches beyond its containing div

I primarily focus on backend development, so my knowledge of html/css is quite limited. However, I have been tasked with creating a new page on a web portal and I could use some assistance. The main issue I am facing relates to the layout structure, which ...

What is the best way to prevent scrolling in one column while allowing another column to scroll normally?

On my website, I have two divs positioned side by side. I am looking to keep one div fixed without scrolling while allowing the second div to scroll normally. How can I achieve this? For a clearer visual, refer to this image: Sample Image ...

Issue with Materialize CSS 'select' not functioning correctly when integrated with Django framework

I am working with a template that gathers all the names of authors from the author_info model. These names are displayed in a dropdown list. However, when I pass the selected value to the view, it ends up displaying null. Here is the template code: <se ...

Using AngularJS to incorporate personalized font icons

Looking to create a custom font icon library similar to "Font Awesome" for my AngularJS project, as using fonts instead of images is more versatile across devices. Is there a way to achieve this? I have generated a font in .ttf and .svg formats with my ...

Setting the height of a span element to 100% within a table using

I have a table with some content inside. One of the elements is an <a class="available">available</a>, but it doesn't fill the entire row of the table. Here is the HTML code: <table with="100%" class="list_table"> <tbody> < ...

Only display one div element when in print mode, hiding all others

My print style CSS code includes the following: * { display:none; } #printableArea { display:block; } Initially, I anticipated that this CSS would hide all elements except for the printableArea. Surprisingly, everything on the page became hidden when ...

Could Chrome be miscalculating em unit values in media queries?

I have defined my media query breakpoints as shown below: @media screen and (max-width:48em){ /* phone */ } @media screen and (min-width:48.063em){ /* tablet */ } After using a PX to EM calculator to get the 48.063em value (as I was advised to us ...

When JavaScript and HTML combine, they create overlapped audio

I am currently working on a project that aims to assist individuals with visual impairments through a website. The main functionality of the site involves playing audio files using keyboard buttons. However, I have encountered an issue where playing one ...

When fetching data from a parse object, JavaScript displayed [object, Object] as the result

When trying to access information from my parse data, I am able to display user table data on my document without any issues. However, when I attempt to query another object and insert it into an id element using jQuery with functions like text();, html(); ...

Improper transformation of raw RGB depth image into grayscale

Working with a Python simulation that includes a depth sensor and C++ visualization has been quite challenging for me. The sensor provides an image that needs to be converted to grayscale. https://i.stack.imgur.com/Dmoqm.png To achieve the conversion, I ...