Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we solve the table row background image problem, in chrome, in multi celled tables?

It is frequently asked – but I haven’t seen a good answer yet (and I looked). If you set a background image in CSS to a table row- the image will repeat itself in every cell. If you set the position: relative (for the row) and set the background-image: none (for the cells) it solves the problem on IE but not on chrome! I can't use background positioning since there are many calls and their size varies. (And the picture is not symmetrical- It's a fade out from one side. Anybody??

Example for the css code :

tr { height: 30px; position:relative;} tr.green { background: url('green_30.png') no-repeat left top; } tr.orange { background: url('oranger_30.png') no-repeat left top;} tr.red { background: url('red_30.png') no-repeat left top; } td { background-image: none; } 

The HTML is basic - A multi cell table.

The goal is to have different colors fade into every row, but it could be any non-pattern image.

like image 549
Ya'el Avatar asked Jun 08 '10 12:06

Ya'el


People also ask

Can a table have a background image?

You can specify an image to set background of your HMTL page or table. Following is the syntax to use background attribute with any HTML tag. The background is deprecated and it is recommended to use Style Sheet for background setting.

How can we change background image in a table cell?

In the table cell tag <td> where you would like to place the background image, paste the image attributes and values. Change the src= attribute name to the background= attribute.

How do you put a background image in a table cell in HTML?

You can add an image background to your HTML table cells by adding BACKGROUND="yourimage. gif" to your <TD> tag.


1 Answers

Ok, I spent ages reading about this, and couldn't find an easy fix for all browsers, but as I see you are using fixed height rows, I've developed my own workaround: http://jsfiddle.net/DR8bM/

Basically, instead of putting the background image on the row, you put it on an absolute-positioned div in the first cell of each row (and expand it to fill the whole row). This is slightly hacky, but may be the only reliable way to achieve what you want.

like image 70
jackocnr Avatar answered Oct 03 '22 22:10

jackocnr