Results 1 to 8 of 8

Thread: translucent background color

  1. #1
    Join Date
    Jun 2008
    Posts
    192
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default translucent background color

    Hello,

    Is there any way to get a background color to a table cell that's translucid (i.e. half transparent/faded)? I have a general background to the body of the page and it remains fixed while the page itself scrolls (so I can't just created a darkened JPG for the table cell background). Any suggestions?

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    yes, but you need to do it in several different ways to make it cross-browser:
    Code:
    /*this makes elements with the class transparent_class 50% opaque*/
    .transparent_class {
    	filter:alpha(opacity=50); /*IE*/
    	-moz-opacity:0.5; /*old netscape*/
    	-khtml-opacity: 0.5; /*old safari*/
    	opacity: 0.5; /*current web standard*/
    }
    taken from css-tricks

  3. #3
    Join Date
    Jun 2008
    Posts
    192
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default

    Thanks traq, but this also makes the contents of the cell transparent, not just the background. Is there any way to incorporate it into the background only?

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    no perfect solution. see this blog at css-tricks.

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Nowadays I would just use a semi-transparent .png image as a background image. This will leave out IE 6, but there are ways to make it render like other browsers if you so choose. However, those still using IE 6 are now thankfully a small minority and a properly constructed semi-transparent .png image used as background will still allow the content over it to be legible, just (probably) not be too pretty in IE 6.

    Also, rather than go through png fix or other strategies to get IE 6 to render your background png properly, one can easily target that browser for an alternate background, like a solid color.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Jun 2009
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Nowadays I would just use a semi-transparent .png image as a background image. This will leave out IE 6, but there are ways to make it render like other browsers if you so choose. However, those still using IE 6 are now thankfully a small minority and a properly constructed semi-transparent .png image used as background will still allow the content over it to be legible, just (probably) not be too pretty in IE 6.

    Also, rather than go through png fix or other strategies to get IE 6 to render your background png properly, one can easily target that browser for an alternate background, like a solid color.
    This will work with IE 6, 7, 8 (wutevermscomesoutwiththatwillbefudgedup)

    http://www.twinhelix.com/css/iepngfix/

    know this, use this, love this.

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Elkidogz View Post
    This will work with IE 6, 7, 8 (wutevermscomesoutwiththatwillbefudgedup)

    http://www.twinhelix.com/css/iepngfix/

    know this, use this, love this.
    There is no reason to use such a strategy with IE 7 and above. These browsers already correctly render alpha channel .png images. However, for IE 5.5 through IE 6 it is a very good strategy, though not perfect. So a word to the wise, use conditional comments to ensure that iepngfix from twinhelix or any any other png fix strategy is only applied to IE 6 and less, otherwise you may inadvertently cause problems in later IE browsers which already have native support for alpha channel .png images.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,920
    Thanks
    2
    Thanked 267 Times in 262 Posts

    Default

    Hi there gib65,

    here is an example for you to try...
    Code:
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta name="language" content="english"> 
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    
    <title></title>
    
    <style type="text/css">
    body{
        background-color:#000;
     }
    #box{
        width:770px;
        height:535px;
        margin:30px auto;
        border:5px double #f60;
        background-image:url(http://www.coothead.co.uk/images/buddha.jpg);
        background-repeat:no-repeat;
     }
    #mytable {
        border:2px inset #333;
        margin:161px auto;
     }
    #mytable td {
        width:324px;
        height:200px;
        border:1px solid #000;
     }
    #container{
        position:relative;
        height:200px;
     }
    #background {
        position:absolute;
        width:324px;
        height:170px;
        padding-top:30px;
        background-color:#f93;
        opacity:0.4;
        filter:alpha(opacity=50);
        font-size:20px;
        font-weight:bold;
        text-align:center;
     }
    #foreground {
        position:absolute;
        width:324px;
        height:200px;
        line-height:200px;
        font-size:20px;
        font-weight:bold;
        text-align:center;
     }
    </style>
    
    </head>
    <body>
    
    <div id="box">
    
    <table id="mytable"><tr>
    
    <td>
    <div id="container">
     <div id="background">This is the Background</div>
     <div id="foreground">This is the Foreground</div>
    </div>
    </td>
    
    </tr></table>
    
    </div>
    
    </body>
    </html>
    
    coothead

    p.s. I would recommend that you reconsider your use of tables for layout purposes.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •