Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to overlay tr with transparent color and text?

Tags:

html

css

Good evening.

I wanted to ask, that is it possible to overlay table row with some transparent color and text?

Something like this: enter image description here

I found from stackoverflow that its possible to overlay over using css, but never managed to get it to work.

If its possible, maybe someone can point me to right way.

For example how to overlay middle table row with transparent color and text here:

<body>

<table border="1" style="width:100%">
  <tr>
    <td>Jill</td>
    <td>Smith</td>      
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>        
    <td>94</td>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>        
    <td>80</td>
  </tr>
</table>

</body>

https://jsfiddle.net/gx2vpm62/ ?

Thanks in advance.

like image 715
user2033139 Avatar asked Nov 22 '15 18:11

user2033139


People also ask

How do you overlay colors in HTML?

We can create an overlay simply by adding a color above an image, decreasing its opacity. For example, create a div tag and give it an id main . Then, create a div inside the header and give it a class overlay . Next, create a paragraph p and write some text.

How do I make the background of text transparent in HTML?

To set the opacity of a background, image, text, or other element, you can use the CSS opacity property. Values for this property range from 0 to 1. If you set the property to 0, the styled element will be completely transparent (ie. invisible).

How do you add an overlay to an image in CSS?

In short, CSS overlay effects are achieved by using the following: background-image and background CSS properties to add image and linear-gradient overlay effect. position:absolute , top , bottom , right , left CSS properties to control the position of overlay image or text.

How do I overlay two images in HTML?

Put your images in there with position: absolute and set top: 0; left:0 . Next you will have to specify z-index to show one on top of the other. You might want to use other properties such as width, height, overflow, display to get the result you are looking for.


1 Answers

You can do this by using an absolutely positioned element in the table. I don't know about cross browser support for this solution and the spacing is static.

.overlay {
  position: absolute;
  background: rgba(255,0,0,0.7);
  left: 0.7em;
  right: 0.7em;
  height: 1.2em;
  text-align: center;
}

tr {
  position: relative;
}
<body>
  <table border="1" style="width:100%">
    <tr>
      <td>Jill</td>
      <td>Smith</td>
      <td>50</td>
    </tr>
    <tr>
      <td>Eve</td>
      <td>Jackson</td>
      <td>94</td>
      <td class="overlay">Text</td>
    </tr>
    <tr>
      <td>John</td>
      <td>Doe</td>
      <td>80</td>
    </tr>
  </table>
</body>
like image 80
0xcaff Avatar answered Sep 19 '22 15:09

0xcaff