stretch a background-image across a table's td using html/css - html

I have a table and want a certain background to be stretched across the width of the TD, whatever the width may be.
My CSS for the relevant td is currently like this:
.tools .theader
{
margin:1px;background-color:#ffffcc;
background:url(../images/td_bg.png) no-repeat center center;
}
and the HTML goes something like this:
<table class'tools'>
<tr>
<td class='theader' colspan=2>
Background
</td>
...
Here's an image of what I get in result:
So you can see the blue bevelled background fits exactly in the center of each td. I want it to stretch to reach the edges of the td so that the whole td looks bevelled. How can this be done?

You can use css gradient instead
HTML
<table class'tools'>
<tr>
<td class='theader' colspan="2">
<span>Background</span>
</td>
</tr>
</table>
CSS
.theader > span{
color:white;
padding:6px 10px;
background: #fffcfc; /* Old browsers */
background: -moz-linear-gradient(top, #fffcfc 0%, #2989d8 12%, #2989d8 51%, #207cca 96%, #ffffff 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#fffcfc), color-stop(12%,#2989d8), color-stop(51%,#2989d8), color-stop(96%,#207cca), color-stop(100%,#ffffff)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #fffcfc 0%,#2989d8 12%,#2989d8 51%,#207cca 96%,#ffffff 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #fffcfc 0%,#2989d8 12%,#2989d8 51%,#207cca 96%,#ffffff 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #fffcfc 0%,#2989d8 12%,#2989d8 51%,#207cca 96%,#ffffff 100%); /* IE10+ */
background: linear-gradient(to bottom, #fffcfc 0%,#2989d8 12%,#2989d8 51%,#207cca 96%,#ffffff 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#fffcfc', endColorstr='#ffffff',GradientType=0 ); /* IE6-9 */
}
DEMO
HERE is the best tool to generate CSS Gradient

Related

table:tr and gradient not working

I want to fill the table row background to x percent.
My problem is that when table cell's width is not 100%, the background color does not appear correctly.
Html :
<table>
<tbody>
<tr id="tr1">
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr id="tr2">
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr id="tr3">
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</tbody>
CSS :
table {
margin: 0 auto;
width: 500px;
border-spacing: 0;
}
#tr1 {
background: #7CB663; /* Old browsers */
background: -moz-linear-gradient(left,#7CB663 50%, #ffffff 50%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top,
color-stop(50%,#7CB663), color-stop(50%,#ffffff)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left,#7CB663 50%,#ffffff 50%); /*Chrome10+,Safari5.1+*/
background: -o-linear-gradient(left,#7CB663 50%,#ffffff 50%); /* Opera 11.10+ */
background: -ms-linear-gradient(left,#7CB663 50%,#ffffff 50%); /* IE10+ */
background: linear-gradient(to right,#7CB663 50%,#ffffff 50%); /* W3C */
background-attachment: fixed;
}
#tr2 {
background: #7CB663; /* Old browsers */
background: -moz-linear-gradient(left,#7CB663 40%, #ffffff 40%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(40%,#7CB663),
color-stop(40%,#ffffff)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left,#7CB663 40%,#ffffff 40%); /*Chrome10+,Safari5.1+*/
background: -o-linear-gradient(left,#7CB663 40%,#ffffff 40%); /* Opera 11.10+ */
background: -ms-linear-gradient(left,#7CB663 40%,#ffffff 40%); /* IE10+ */
background: linear-gradient(to right,#7CB663 40%,#ffffff 40%); /* W3C */
background-attachment: fixed;
}
#tr3 {
background: #7CB663; /* Old browsers */
background: -moz-linear-gradient(left,#7CB663 20%, #ffffff 20%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(20%,#7CB663),
color-stop(20%,#ffffff)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left,#7CB663 20%,#ffffff 20%); /*Chrome10+,Safari5.1+*/
background: -o-linear-gradient(left,#7CB663 20%,#ffffff 20%); /* Opera 11.10+ */
background: -ms-linear-gradient(left,#7CB663 20%,#ffffff 20%); /* IE10+ */
background: linear-gradient(to right,#7CB663 20%,#ffffff 20%); /* W3C */
background-attachment: fixed;
}
td {
border: 1px solid #000;
}
Output :
Has anyone a good solution for this problem?
I'm assuming your problem is that the gradient stops aren't relative to the table width, but to the width of body.
Looks like that's because you're setting background-attachment: fixed. Getting rid of that property did the trick for me.
edited JSfiddle
it is because your background gradient has been stopped at 50%, if you need to display color in full tr width, use following css
background: rgba(0, 0, 0, 0) linear-gradient(to right, #7cb663 50%, #ffffff 100%) repeat fixed 0 0;
this css will help you to repeat color in full width.

Display image on a gradient background on hover via css

I have this background:
.background:hover {
background: #F4F4F4 url(../images/arrow_down_over.gif) no-repeat right;
}
that I would like to change into a gradient like this one :
.background:hover{
background: -moz-linear-gradient(top, #f4f4f4 0%, #eeeeee 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f4f4f4), color-stop(100%,#eeeeee)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #f4f4f4 0%,#eeeeee 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #f4f4f4 0%,#eeeeee 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #f4f4f4 0%,#eeeeee 100%); /* IE10+ */
background: linear-gradient(to bottom, #f4f4f4 0%,#eeeeee 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f4f4f4', endColorstr='#eeeeee',GradientType=0 );
} /* IE6-9 */
But I would like to keep the arrow image. I can't find a way to do it. I did try something like this:
background: -moz-linear-gradient(top, #f4f4f4 0%, #eeeeee 100%) url(../images/arrow_down_over.gif) no-repeat right; /* FF3.6+ */
or add this after the gradient properties but without any success.
background: url(../images/arrow_down_over.gif) no-repeat right;
I can't add another class so I have to deal with this CSS. Any idea how to do it?
You may try:
background: url(../images/arrow_down_over.gif), linear-gradient(...);
Multiple backgrounds must be comma-separated rather than space-separated, and they weirdly stack from top to bottom.
Also note that this is not necessarily supported by all browsers.
See http://css-tricks.com/stacking-order-of-multiple-backgrounds/ and https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Using_multiple_backgrounds for details

Building a Product Box using images w/ CSS

I designed a very basic looking box in Photoshop that I would like to use to show product information inside of. It basically consists of a Header, Body and Button (each a separate image) that look like the image below.
How can I use CSS/HTML to piece these together? I just need to show header text in the top box and bullet points in the body area, but not sure how to actually build this from the image files.
I know the HTML will look as such, I am just confused as to how to actually build the box, such as stacking the images and overlaying the button in that position over the body.
<div id="product_box">
<div id="header">Title Here</div>
<div id="body">
<ul>
<li>Point here</li>
<li>Point here</li>
<li>Point here</li>
</ul>
</div>
<div id="button></div>
</div>
Well Have a look at:
http://jsfiddle.net/2A2Fn/4/
You don't have to change your html markup just use css:
Here is relevant CSS:
#product_box{
border:2px solid #bbc;
border-radius:15px;
display:block;
width:50%;
height:100%;
position:relative;
box-shadow: 5px 5px 5px rgba(0,0,0,0.5);
padding:0px; !important
background: #b5bdc8; /* Old browsers */
/* Gradient */
background: -moz-linear-gradient(top, #b5bdc8 0%, #828c95 36%, #28343b 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#b5bdc8), color-stop(36%,#828c95), color-stop(100%,#28343b)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #b5bdc8 0%,#828c95 36%,#28343b 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #b5bdc8 0%,#828c95 36%,#28343b 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #b5bdc8 0%,#828c95 36%,#28343b 100%); /* IE10+ */
background: linear-gradient(to bottom, #b5bdc8 0%,#828c95 36%,#28343b 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b5bdc8', endColorstr='#28343b',GradientType=0 ); /* IE6-9 */
}
#header{
background:#aaf;
width:100%;
height:50px;
border:0px;
border-bottom:1px solid #99b;
padding-top:15px;
padding-bottom:15px;
border-radius:5px;
background: #b5bdc8; /* Old browsers */
/* gradient */
background: -moz-linear-gradient(top, #b5bdc8 0%, #828c95 36%, #28343b 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#b5bdc8), color-stop(36%,#828c95), color-stop(100%,#28343b)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #b5bdc8 0%,#828c95 36%,#28343b 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #b5bdc8 0%,#828c95 36%,#28343b 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #b5bdc8 0%,#828c95 36%,#28343b 100%); /* IE10+ */
background: linear-gradient(to bottom, #b5bdc8 0%,#828c95 36%,#28343b 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b5bdc8', endColorstr='#28343b',GradientType=0 ); /* IE6-9 */
}
#body{
padding-bottom:15px;
}
#button{
background:#756;
border:1px solid #645;
display:block;
width:150px;
height:50px;
border-radius:5px;
position:absolute;
bottom:-25px;
right:33%;
color:#fff;
box-shadow:5px 5px 5px rgba(0,0,0,0.4);
text-align:center;
font-weight:bolder;
font-size:15px;
background: #b5bdc8; /* Old browsers */
/* Gradient */
background: -moz-linear-gradient(top, #b5bdc8 0%, #828c95 36%, #28343b 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#b5bdc8), color-stop(36%,#828c95), color-stop(100%,#28343b)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #b5bdc8 0%,#828c95 36%,#28343b 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #b5bdc8 0%,#828c95 36%,#28343b 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #b5bdc8 0%,#828c95 36%,#28343b 100%); /* IE10+ */
background: linear-gradient(to bottom, #b5bdc8 0%,#828c95 36%,#28343b 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b5bdc8', endColorstr='#28343b',GradientType=0 ); /* IE6-9 */
}
div{
text-align:center;
color:#fff;
font-weight:bold;
}
And Here is output of that:
EDIT
According to your comment here is updated code:
http://jsfiddle.net/2A2Fn/5/
and its output:
Hope it helps.
It can be done using only HTML/CSS.
Use CSS gradient for it.
Here is the DEMO
Seeing your CSS code would help. This is how I would achieve what you want:
Set a div element to the desired height of the box. Apply a border and border-radius property as desired, probably 2 px border and a radius of 10-15 px.
Take the header image, and crop it down to 1 pixel wide (for memory conservation). Then set a div element and use this 1pixel wide image as the background, repeat x, but not y. Set the height of the header to the height of the gradient image.
Then, make another div inside the container div. Take your second gradient image and again reduce it to a 1 pixel width. Set it as the background for this div with repeat-x. You'll have to set the height of the header div to the difference of the height of the header and the height of the container.
Your button can then be placed as a link, probably in another div element.
All this can be coded something like as follows:
CSS:
div.container
{
height: 400px;
width: 300px;
border: 2px solid #000;
border-radius: 12px;
}
div.header
{
background-image: url("header-grad.ext");
background-repeat: repeat-x;
height: 40px;
width: 100%;
}
div.content
{
background-image: url("content-grad.ext");
background-repeat: repeat-x;
height: 360px;
width: 100%;
}
And the HTML:
<div class="container">
<div class="header">text here</div>
<div class="content"><\div>
<div class="button></div>
</div>
This should do what you want. You'll need to specify the button CSS as well which I didn't do as I'm on mobile right now.
Hope this helps you!

Two background colors (Horizontal)

I'am wondering If It's possible to have two different colors in the background, expanding 100% with bootstrap, en each side.
Here is a screenshot of what i mean,
Red on the left side, dark on the right side, expanding 100% for bigger screens. Any easy solutions for this?
There are a couple ways to do this. The best way uses pseudo-elements. You'd apply one color to the <body>, and the second color to a created :after element.
HTML:
<body>
<main>
<p>This is my first paragraph.</p>
<p>This is my second paragraph.</p>
Page continues...
CSS:
body {
background-color:rgb(155,155,155);
}
body:after {
top:0;
left:0;
width:40%;
height:100%;
position:absolute;
z-index:-1;
background-color:rgb(239,0,0);
content:"";
}
main {
width:80%;
margin:0 auto;
background-color:white;
min-height:400px;
padding:20px;
}
http://jsfiddle.net/Q66Xn/3/
This answer produces the cleanest code. Disadvantages: Limited IE8 support, no IE7 support. If you need to use those two browsers, then see the next option:
Give the <body> the same background color of one side, then instead of using :after to create a pseudo-element, we just create a real element.
HTML:
<body>
<div id="bgleft"></div>
<main>
<p>This is my first paragraph.</p>
<p>This is my second paragraph.</p>
Page continues...
CSS:
body {
background-color:rgb(155,155,155);
}
#bgleft {
top:0;
left:0;
width:40%;
height:100%;
position:absolute;
z-index:-1;
background-color:rgb(239,0,0);
}
main {
width:80%;
margin:0 auto;
background-color:white;
min-height:400px;
padding:20px;
}
http://jsfiddle.net/Q66Xn/4/
The produces exactly the same as the first method. The advantage is higher browser compatibility, with a disadvantage of a little bit more code.
Finally, you could use a gradient attached to the body. This will give both colors on the single body element, saving extra HTML, but it'll by a nasty set of CSS to support all browsers:
body {
background: rgb(239,0,0); /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2VmMDAwMCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjQ0JSIgc3RvcC1jb2xvcj0iI2VmMDAwMCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjQ0JSIgc3RvcC1jb2xvcj0iIzliOWI5YiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiM5YjliOWIiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(left, rgb(239,0,0) 0%, rgb(239,0,0) 44%, rgb(155,155,155) 44%, rgb(155,155,155) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgb(239,0,0)), color-stop(44%,rgb(239,0,0)), color-stop(44%,rgb(155,155,155)), color-stop(100%,rgb(155,155,155))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, rgb(239,0,0) 0%,rgb(239,0,0) 44%,rgb(155,155,155) 44%,rgb(155,155,155) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, rgb(239,0,0) 0%,rgb(239,0,0) 44%,rgb(155,155,155) 44%,rgb(155,155,155) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, rgb(239,0,0) 0%,rgb(239,0,0) 44%,rgb(155,155,155) 44%,rgb(155,155,155) 100%); /* IE10+ */
background: linear-gradient(to right, rgb(239,0,0) 0%,rgb(239,0,0) 44%,rgb(155,155,155) 44%,rgb(155,155,155) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ef0000', endColorstr='#9b9b9b',GradientType=1 ); /* IE6-8 */
}
http://jsfiddle.net/Q66Xn/
Disadvantages: Complex CSS which is difficult to easily edit later on.
You're issue isn't related to bootstrap specific, as Ollie stated.
Some of your options are, using a gradient, or a sliver (a 1px width/height image, which you repeat on which ever axis).
I find using a gradient generator works quite well for most of my new projects I need to startup. I've attached an example for you to try.
Example
http://jsfiddle.net/wLw4r/4/
Markup
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<h2 style="color: white">Something</h2>
</div>
</div>
<div class="row ">
<div class="jumbotron">
<h2>YOLO</h2>
<div class="row">
<div class="col-md-4">Something</div>
<div class="col-md-3">Something</div>
<div class="col-md-3">Something</div>
<div class="col-md-2">Something</div>
</div>
</div>
</div>
</div>
</body>
CSS
body {
background: rgb(169,3,41); /* Old browsers */
background: -moz-linear-gradient(left, rgb(169,3,41) 0%, rgb(143,2,34) 26%, rgb(143,2,34) 26%, rgb(0,0,0) 26%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgb(169,3,41)), color-stop(26%,rgb(143,2,34)), color-stop(26%,rgb(143,2,34)), color-stop(26%,rgb(0,0,0))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, rgb(169,3,41) 0%,rgb(143,2,34) 26%,rgb(143,2,34) 26%,rgb(0,0,0) 26%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, rgb(169,3,41) 0%,rgb(143,2,34) 26%,rgb(143,2,34) 26%,rgb(0,0,0) 26%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, rgb(169,3,41) 0%,rgb(143,2,34) 26%,rgb(143,2,34) 26%,rgb(0,0,0) 26%); /* IE10+ */
background: linear-gradient(to right, rgb(169,3,41) 0%,rgb(143,2,34) 26%,rgb(143,2,34) 26%,rgb(0,0,0) 26%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#a90329', endColorstr='#000000',GradientType=1 ); /* IE6-9 */
}
You will struggle to do this using only bootstrap.
You could achieve the result you are after using linear gradients: http://codepen.io/ollieRogers/pen/snjkw this would need a fallback for browsers that do not support gradient bgs.
body{
background: #49191a; /* Old browsers */
background: -moz-linear-gradient(left, #49191a 0%, #49191a 30%, #53cbf1 30%, #53cbf1 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,#49191a), color-stop(30%,#49191a), color-stop(30%,#53cbf1), color-stop(100%,#53cbf1)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, #49191a 0%,#49191a 30%,#53cbf1 30%,#53cbf1 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, #49191a 0%,#49191a 30%,#53cbf1 30%,#53cbf1 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, #49191a 0%,#49191a 30%,#53cbf1 30%,#53cbf1 100%); /* IE10+ */
background: linear-gradient(to right, #49191a 0%,#49191a 30%,#53cbf1 30%,#53cbf1 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#49191a', endColorstr='#53cbf1',GradientType=1 ); /* IE6-9 */
}

How do I make buttons stay active rather than revert to normal state?

I want touchscreen buttons that stay depressed while the page is active rather than revert to normal state.
Is there a simple solution to this?
Ie, you're on the main page, there are three buttons, you press a button, it takes you to the new page and shades a different color.
The code I'm working with looks like this:
HTML:
<input type="button" value="Name" class="Class" onclick="location.href='#';">
CSS:
.class {display:inline;border:solid #000 3px;margin-left:auto;margin-right:auto;padding:10px;font-family: 'helvetica neue', helvetica, arial;font-size:16px;font-weight:600;
color:#fff; -webkit-border-radius: 0.5em; -moz-border-radius: 0.5em; border-radius: 0.5em;
background: #aaa; /* Old browsers */
background: -moz-linear-gradient(top, #636363 0%, #ffffff 4%, #000000 75%, #ffff00 97%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#636363), color-stop(4%,#ffffff), color-stop(75%,#000000), color-stop(97%,#ffff00)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #636363 0%,#ffffff 4%,#000000 75%,#ffff00 97%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #636363 0%,#ffffff 4%,#000000 75%,#ffff00 97%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #636363 0%,#ffffff 4%,#000000 75%,#ffff00 97%); /* IE10+ */
background: linear-gradient(to bottom, #636363 0%,#ffffff 4%,#000000 75%,#ffff00 97%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#636363', endColorstr='#ffff00',GradientType=0 ); /* IE6-9 */
}
.class:active {background: #bababa; /* Old browsers */
background: -moz-linear-gradient(top, #bababa 1%, #636363 69%, #000000 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(1%,#bababa), color-stop(69%,#636363), color-stop(100%,#000000)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #bababa 1%,#636363 69%,#000000 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #bababa 1%,#636363 69%,#000000 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #bababa 1%,#636363 69%,#000000 100%); /* IE10+ */
background: linear-gradient(to bottom, #bababa 1%,#636363 69%,#000000 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#bababa', endColorstr='#000000',GradientType=0 ); /* IE6-9 */
}
What i would do is assign some sort off 'active' class to the link (eather on the server side, of by using some javascript), and give it the same styling as your hover state. Something like this:
#menu a:hover, #menu a.active {
background: #[PressedStateColor];
}
You could add the 'active' class with some easy javascript (jQuery) like this:
// when the dom is ready
$(document).ready(function() {
// for each of the links in the #menu
$('#menu a').each(function() {
// if the href of the link matches the one for the current page
if ($(this).attr('href') == window.location.href) {
// add the class 'active' to the link
$(this).addClass('active');
}
});
});
Note that this is not foolproof, it will only work on simple url's. Personally I would go for a server side solution.
To demonstrate, I set up a little fiddle: http://jsfiddle.net/RyHse/