Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying a single background gradient to a table row

Tags:

css

Is it possible to have a background gradient that spans an entire table row? I'm only able to apply the background to individual table cells, even when I'm specifically trying to prevent that. Here is a boiled-down sample that targets Webkit on jsfiddle:

http://jsfiddle.net/cGV47/2/

As you can see, I am using border-collapse:collapse and I am specifying background:transparent for the <tr> and <th> child elements, yet the red gradient to the left is repeated for each table cell. I've tried applying the background to the <tr> as well, but with the same result as you see now.

To view the code without going to jsfiddle, here it is:

html

<table>     <thead>         <tr>             <th>One</th>             <th>Two</th>             <th>Three</th>             <th>Four</th>         </tr>     </thead>     <tbody>         <tr>             <td>un</td>             <td>deux</td>             <td>trois</td>             <td>quatre</td>         </tr>     </tbody> </table> 

css

* {margin:0;padding:0;border:0;border-collapse:collapse;} table { width:100%; } thead { background: -webkit-linear-gradient(left, rgba(222,22,22,1) 0%, rgba(222,222,222,0) 20%, rgba(222,222,222,0) 80%, rgba(222,222,222,1) 100%); } thead tr, thead th { background:transparent; } 
like image 269
Andrew Avatar asked Jan 17 '13 03:01

Andrew


People also ask

How do you add a background color to a row in a table?

HTML | <tr> bgcolor Attribute The HTML <tr> bgcolor Attribute is used to specify the background color of a table row. It is not supported by HTML 5. Attribute Values: color_name: It sets the background color by using the color name.

Can we set a background color just for one cell in a table?

In HTML, table background color is defined using Cascading Style Sheets (CSS). Specifically, you use the background-color property to define background color. You can apply this property against the whole table, a row, or a single cell.

Is it possible to add a gradient background to an element without using an image?

You can also easily add a gradient background to a div (or any other HTML element) without using images, using the following CSS rules. BTW, I've set the gradient to start at red and end in blue.


1 Answers

set background-attachment:fixed; on thead and it will work fine

http://jsfiddle.net/cGV47/64/

like image 114
jekcom Avatar answered Sep 23 '22 02:09

jekcom