position an image directly on top of the table with a slight transparency

I'm looking to display the image attached above a table with some transparency. The challenge I'm facing in my current code is that the image is appearing below the table instead of across it. Additionally, I need the image to be wrapped in a div or similar container with transparent properties that cover the entire table.

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
  box-sizing: border-box;
}

body {
  font-family: Arial;
  font-size: 17px;
}

.container {
  position: absolute;
  max-width: 400px;
}

.container img {vertical-align: middle;}

.container .content {
position: relative;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;  
  background: rgb(0, 0, 0); /* Fallback color */
  background: rgba(255, 255, 255, 0.5); /* Black background with 0.5 opacity */  

font-size: 50px; 
text-align: center; 
font-style: italic; 
padding: 40px; 
padding-top: 180px; 
color: grey;
    /* Rotate div */
    -ms-transform: rotate(-25deg); /* IE 9 */
    -webkit-transform: rotate(-25deg); /* Chrome, Safari, Opera */
    transform: rotate(-25deg);
}
</style>
</head>
<body>

<h2>Responsive Image with Transparent Text</h2>

<div class="container"> 
<TABLE width="800px">
<TR>
<TD>Test</TD>
<TD>Test</TD>
<TD>Test</TD>
</TR>
<TR>
<TD>Test</TD>
<TD>Test</TD>
<TD>Test</TD>
</TR>
<TR>
<TD>Test</TD>
<TD>Test</TD>
<TD>Test</TD>
</TR>
<TR>
<TD>Test</TD>
<TD>Test</TD>
<TD>Test</TD>
</TR>
<TR>
<TD>Test</TD>
<TD>Test</TD>
<TD>Test</TD>
</TR>
</TABLE>
  <div class="content">    
    <IMG SRC="ComingSoon.png" WIDTH="548" HEIGHT="53" BORDER="0" ALT="">
  </div>
</div>

</body>
</html>

https://i.sstatic.net/ixqmn.png

Answer №1

Creating links that cannot be clicked by placing an image over them may seem like a bit of a workaround, but sometimes a quick and clever solution is all you need! Here's a simple guide to achieve this:

1. Swap the positioning attributes of .container and .container .content.

(Make .container relative and .container .content absolute.)

By making .container .content absolute, it will overlay the table.

You could technically keep .container as absolute too, but I would advise against it due to how CSS positioning works: absolute positioning is not necessarily based on the entire page, but rather on the next positioned ancestor (an element with a position property). It's crucial that .container is positioned to ensure that your image doesn't obstruct the headline. Simply giving it any position value will suffice, but using relative is safer in this scenario as it won't impact the element's position unless specific left/right/top/bottom properties are defined. Absolute positioning, on the other hand, could potentially disrupt your overall layout.

2. Do not rotate .container .content; instead, rotate .container .content img.

Rotating .container .content caused it to partially cover the headline.

3. Remove bottom: 0 and right: 0 from .container .content.

Although this step isn't essential for achieving your goal, these properties are unnecessary. When positioning an element, you only need to specify its distance from either top or bottom, as well as left or right. Including both properties will result in browsers disregarding one (likely the first one).

I hope my explanations have been clear and helpful!

Cheers!

Answer №2

It seems like your current CSS rules may not be aligned with what you're attempting to achieve.

You've mixed up the CSS rules for the content div and the image inside it. If you want to rotate the image, apply the transformation only to the img tag and focus on adjusting padding and background color within the div to cover the entire table without affecting the image. By keeping both the content div and the img positioned absolutely, they can overlap each other and the table while allowing for easy manipulation (ensure the div is wide enough to cover the content).

Below is my suggestion, although some adjustments may be needed for the size and position of the image. I believe it aligns closely with what you described.

<!DOCTYPE html>
<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <style>
    * {
      box-sizing: border-box;
    }
    
    body {
      font-family: Arial;
      font-size: 17px;
    }
    
    .container {
      position: absolute;
      max-width: 800px;
    }
    
    .container img {
      position: absolute;
      top: 10%;
      left: 25%;
      vertical-align: middle;
      /* Rotate div */
      -ms-transform: rotate(-25deg);
      /* IE 9 */
      -webkit-transform: rotate(-25deg);
      /* Chrome, Safari, Opera */
      transform: rotate(-25deg);
    }
    
    .container .content {
      position: absolute;
      top: 0;
      left: 0;
      background: rgb(0, 0, 0);
      /* Fallback color */
      background: rgba(255, 255, 255, 0.5);
      /* Black background with 0.5 opacity */
      font-size: 50px;
      width: 100%;
      text-align: center;
      font-style: italic;
      color: grey;
    }
  </style>
</head>

<body>

  <h2>Responsive Image with Transparent Text</h2>

  <div class="container">
    <div class="content">
      <IMG SRC="https://i.sstatic.net/ixqmn.png" WIDTH="200" HEIGHT="53" BORDER="0" ALT="">
    </div>
    <TABLE width="800px">
      <TR>
        <TD>Test</TD>
        <TD>Test</TD>
        <TD>Test</TD>
      </TR>
      <TR>
        <TD>Test</TD>
        <TD>Test</TD>
        <TD>Test</TD>
      </TR>
      <TR>
        <TD>Test</TD>
        <TD>Test</TD>
        <TD>Test</TD>
      </TR>
      <TR>
        <TD>Test</TD>
        <TD>Test</TD>
        <TD>Test</TD>
      </TR>
      <TR>
        <TD>Test</TD>
        <TD>Test</TD>
        <TD>Test</TD>
      </TR>
    </TABLE>
  </div>

</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

Newbie Question: What is the process to upload a website that consists of only HTML files to a web hosting provider

I'm embarking on creating a basic four-page website using HTML, CSS, and images. It's my maiden voyage into web design. When I finish developing the HTML files, what steps should I take to upload them and launch the website? ...

jQuery not loading SCRIPT src after appending to HTML

I'm in the process of developing an application that requires me to load new HTML content and append it into the current page's HTML. So far, I've been able to load the new HTML using jQuery ajax. However, within this newly loaded HTML, the ...

.htaccess 404 not redirecting properly

I need help with the following code snippet: # Keep this line intact for mod_rewrite rules to function properly RewriteBase / ErrorDocument 404 /errors/404.php Despite having the file 404.php in the errors folder, it doesn't seem to be working as ...

"Ensure div remains at the bottom of the page even while

In order to implement a feature where the menu sticks to the top when scrolling down, you can use the following JS code. You can view a live example of this functionality on this Plunker by widening the preview window to see the columns side by side. wi ...

What could be causing my footer to appear anywhere but the bottom of the page?

I have been struggling to position the footer of my webpage at the bottom, but it seems to be stuck in the middle. Despite watching tutorial videos and attempting to follow along, I haven't been able to resolve this issue. Admittedly, my code is a b ...

Is there a way to modify the color scheme of the hamburger icon

I'm experiencing difficulties changing the color of a hamburger icon. I've searched for the specific code responsible for the color change, but I haven't been able to locate it. Ideally, I want the color to be white, but on small screens, i ...

Incorporating CSS style to individual rows in an HTML table

Is there a way to determine if a specific string, such as 'LA DEFENSE', is present in my HTML table and then change the background color of that line to red? https://i.sstatic.net/Yq7qF.png This is what I am looking for: $("#colorline").click( ...

Tips for adding a personalized close button to a Bootstrap modal

I need help with a Bootstrap modal in my project that has a close button positioned at the top right corner. I've used CSS to position the button, but it's not staying in one place consistently despite applying absolute positioning. I've tri ...

Adjust the size of CSS boxes based on the window dimensions

I am facing an issue with two divs placed side by side. They appear fine when the page is viewed in full-screen mode. However, upon resizing the window, the right div overlaps the left one and causes a messy layout. . -I want to prevent these boxes fro ...

The link in the navigation bar is not functioning correctly

Let me break down the issue I'm facing here. The problem arises with the navigation buttons that have sub-lists nested within them (ul>li>ul). When attempting to click on these buttons, the link does not work unless I specifically click on the t ...

What causes the delay in CSS animations?

Is there a way to trigger an "updating" image to spin while a long JavaScript function is running? I am currently using JQuery to add a class called "spinning", defined in my CSS for the animation. The problem is that when I add the class and then call a l ...

Creating an expandable search box that overflows other content: A step-by-step guide

I am facing an issue with a search box that expands when activated. However, I want the search box to break out of the Bootstrap column and overflow other content on the page. How can I achieve this? Here is the CSS code for the search box styling: .searc ...

Protected login form

I've designed a login form that prompts users to enter their username and password in order to access index.php. Additionally, I have authenticate.php set up, which is required by index.php to prevent unauthorized access. However, I'm struggling ...

Embedding a CSS file into a PHP class

I've encountered a little issue that I can't seem to solve on my own. I've put together a "webengine" using multiple classes. The primary class responsible for obtaining a theme's internals is called "Logic". This Logic class contain ...

The use of a custom padding on a text input with the Bootstrap 3 form-control class can cause the text to be hidden

It seems like the code is working fine in Opera and Chrome, but in Firefox and IE11, the text is getting hidden, which is not very enjoyable. I don't have a Mac, so I can't test it on Safari. You can see the issue in action on this Plunker. I&a ...

Customizing the appearance of input range in Firefox

I am having trouble styling the HTML input range element. I have successfully styled it for webkit browsers, but my styling does not seem to work on -moz- browsers. I attempted to use pseudo elements before and after on moz-range-thumb, but it seems that F ...

Drop-Menu - Tubular Formation of Columns

I am currently facing a challenge in creating a filter on a web page using Bootstrap's drop-down menu. The issue lies in placing the filters in columns side by side, as they are stacking up instead. The filter menu is generated dynamically by looping ...

Creating a CSS background that adjusts to fit any screen resolution

Hey there, I'm a beginner to all of this. I want my background image to adjust to fit any web browser resolution, regardless of the size. So far, I've come across this nifty little trick: html { background: url(images/bg.jpg) no-repeat center ...

The vertical dimension of an element does not increase

Currently, I am working on a webpage with a header, page content, and footer sections. The issue I'm facing is that I set the page's height to height :auto;, but it's not functioning as expected. I actually need the page to automatically ex ...

The Troubles of Top Margins in CSS

Hey there, I'm a bit stumped on this issue. I've been trying to apply a 10px top margin to a paragraph inside a div, but instead of creating the space I want between elements, it just seems to push the whole containing div down by 10px. Here are ...