Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. CSS only Transparent background in DIV with child elements opaque

CSS only Transparent background in DIV with child elements opaque

Scheduled Pinned Locked Moved Web Development
helphtmlcssquestion
15 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Give this a try. Replace the .body_child with whatever class name you have used. The wrapper should give you 50% opacity (transparency) and the transparency removed for the child.

    .body_wrapper {
    padding: 0 20px 20px;
    -webkit-border-radius: 5px;
    _display: inline;
    background-color: #000000; /* the background */
    filter:alpha(opacity=50); /* Internet Explorer */
    -moz-opacity:0.5; /* Mozilla 1.6 and below */
    -webkit-opacity:0.5; /* Safari */
    opacity: 0.5; /* newer Mozilla and CSS-3 */
    }
    .body_child {
    filter:alpha(opacity=100);
    -moz-opacity:1.0;
    opacity: 1.0;
    -webkit-opacity: 1.0;
    }

    D Offline
    D Offline
    Dave McCool
    wrote on last edited by
    #3

    Hi Richard, that seems like a great solution, but I came across a snag, not to do with the code you posted (it would work fine) but more to myself, a small problem that I created meaning I can't use that code. All the code for child elements inside the body_wrapper are on my webpages, not my CSS and now I have over 300 webpages and can't go in and put the code in the CSS file as it would take to long to put the code there and remove the code from each page :sigh: I had an idea though but couldn't find a solution that uses a CSS file only. I have a background image I wanted to use instead of this:

    background-color: #000000; /* the background */

    Now I wanted the whole image to be 50% transparent like what I wanted to do before I realised my screw up. I have looked about and only found ways of making parts of the image transparent when you insert them on a webpage, but is is possible to make the whole image semi transparent? This would solve my issue then as the image would be transparent and I wouldn't have to modify any more code to fix the parent/child transparecy issue. Thanks David McCormick

    In the end we're all just the same

    L 2 Replies Last reply
    0
    • D Dave McCool

      Hi Richard, that seems like a great solution, but I came across a snag, not to do with the code you posted (it would work fine) but more to myself, a small problem that I created meaning I can't use that code. All the code for child elements inside the body_wrapper are on my webpages, not my CSS and now I have over 300 webpages and can't go in and put the code in the CSS file as it would take to long to put the code there and remove the code from each page :sigh: I had an idea though but couldn't find a solution that uses a CSS file only. I have a background image I wanted to use instead of this:

      background-color: #000000; /* the background */

      Now I wanted the whole image to be 50% transparent like what I wanted to do before I realised my screw up. I have looked about and only found ways of making parts of the image transparent when you insert them on a webpage, but is is possible to make the whole image semi transparent? This would solve my issue then as the image would be transparent and I wouldn't have to modify any more code to fix the parent/child transparecy issue. Thanks David McCormick

      In the end we're all just the same

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #4

      David, You might be able to do something like

      .body_wrapper {
      background-image:url(path_to/image_name.jpg); /* add repeat or no-repeat or repeat-x or repeat-y as necessary (or not at all) */
      height:100%; /* use as necessary */
      filter:alpha(opacity=50);
      -moz-opacity:0.5;
      -webkit-opacity:0.5;
      opacity: 0.5;
      }

      Because of CSS inheritance rules http://www.w3.org/TR/CSS2/cascade.html[^], the above might not do what you want

      1 Reply Last reply
      0
      • D Dave McCool

        Hi Richard, that seems like a great solution, but I came across a snag, not to do with the code you posted (it would work fine) but more to myself, a small problem that I created meaning I can't use that code. All the code for child elements inside the body_wrapper are on my webpages, not my CSS and now I have over 300 webpages and can't go in and put the code in the CSS file as it would take to long to put the code there and remove the code from each page :sigh: I had an idea though but couldn't find a solution that uses a CSS file only. I have a background image I wanted to use instead of this:

        background-color: #000000; /* the background */

        Now I wanted the whole image to be 50% transparent like what I wanted to do before I realised my screw up. I have looked about and only found ways of making parts of the image transparent when you insert them on a webpage, but is is possible to make the whole image semi transparent? This would solve my issue then as the image would be transparent and I wouldn't have to modify any more code to fix the parent/child transparecy issue. Thanks David McCormick

        In the end we're all just the same

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #5

        As an alternative, instead of editing file by file the code within those 300 pages, you could use Notepad++ [^] and do similar to this [^]or you may be able to do a similar thing with Windows Grep [^]. That's just a thought for you ...

        1 Reply Last reply
        0
        • D Dave McCool

          I have a slight issue, tried everything to make this work, half the time I can get the background to be 100% transparent so you don't see it and have the other child elements opaque, but all I want is the background to be 50% transparent so the main background is showing through it. First, here is an image of one of the pages. I want the black border to be semi transparent (50%) but everything else inside this area to appear as it is 100% opaque (that is all child elements inside the body_wrapper): http://img697.imageshack.us/img697/8008/webpage.jpg[^] Here is the code in my CSS file that controls the DIV tag (the "background: #000000;" is the black background code that I wanted to have semi transparent:

          .body_wrapper {

          padding: 0 20px 20px;
          background: #000000;
          -webkit-border-radius: 5px;
          \_display: inline;
          

          }

          The only thing is that I can't modify anything on my HTML pages as I have too many and have to do all this with my CSS file. I have been looking all over and tried a few things but nothing seems to work, can anyone help?

          In the end we're all just the same

          D Offline
          D Offline
          dawmail333
          wrote on last edited by
          #6

          Try this:

          .body_wrapper
          {
          background-color: rgba(0,0,0,0.5);
          }

          It will work in browsers that support CSS3, which is becoming more common. Don't know about earlier IE's in particular though, I'm sorry to say. The above code simply sets the div to have a semi-transparent background (approx. 50% black). It's called ARGB. HTH.

          modified on Saturday, August 7, 2010 3:11 AM

          D 1 Reply Last reply
          0
          • D dawmail333

            Try this:

            .body_wrapper
            {
            background-color: rgba(0,0,0,0.5);
            }

            It will work in browsers that support CSS3, which is becoming more common. Don't know about earlier IE's in particular though, I'm sorry to say. The above code simply sets the div to have a semi-transparent background (approx. 50% black). It's called ARGB. HTH.

            modified on Saturday, August 7, 2010 3:11 AM

            D Offline
            D Offline
            Dave McCool
            wrote on last edited by
            #7

            Thanks all got it :) . I tried the rgba(0,0,0,0.5); and it worked, but not on IE so I thought and then did this and now it works in IE: .Body_Wrapper { background-color: rgba(0,0,0,0.5); filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#80000000,endColorstr=#80000000); zoom: 1; /* Force hasLayout in IE. */ }

            In the end we're all just the same

            D 1 Reply Last reply
            0
            • D Dave McCool

              Thanks all got it :) . I tried the rgba(0,0,0,0.5); and it worked, but not on IE so I thought and then did this and now it works in IE: .Body_Wrapper { background-color: rgba(0,0,0,0.5); filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#80000000,endColorstr=#80000000); zoom: 1; /* Force hasLayout in IE. */ }

              In the end we're all just the same

              D Offline
              D Offline
              dawmail333
              wrote on last edited by
              #8

              Glad to help. ;)

              Posted from SPARTA!!!!!!!!!! 2.0. Don't forget to rate my post if it helped! ;)

              D 1 Reply Last reply
              0
              • D dawmail333

                Glad to help. ;)

                Posted from SPARTA!!!!!!!!!! 2.0. Don't forget to rate my post if it helped! ;)

                D Offline
                D Offline
                Dave McCool
                wrote on last edited by
                #9

                I have only one issue with the code, although it works and now works on IE, on IE any text in child elements does not look smooth: Page on IE: http://img339.imageshack.us/img339/5572/webpageie.jpg[^] Same page on Google Chrome: http://img839.imageshack.us/img839/985/webpagechrome.jpg[^] Is there any way of making the text in the child elements appear normal in IE?

                In the end we're all just the same

                D L 2 Replies Last reply
                0
                • D Dave McCool

                  I have only one issue with the code, although it works and now works on IE, on IE any text in child elements does not look smooth: Page on IE: http://img339.imageshack.us/img339/5572/webpageie.jpg[^] Same page on Google Chrome: http://img839.imageshack.us/img839/985/webpagechrome.jpg[^] Is there any way of making the text in the child elements appear normal in IE?

                  In the end we're all just the same

                  D Offline
                  D Offline
                  dawmail333
                  wrote on last edited by
                  #10

                  Using proprietary filters in IE generally causes strange side effects. All I can say: http://dowebsitesneedtolookexactlythesameineverybrowser.com/ ;P

                  Posted from SPARTA!!!!!!!!!! 2.0. Don't forget to rate my post if it helped! ;)

                  D 1 Reply Last reply
                  0
                  • D Dave McCool

                    I have only one issue with the code, although it works and now works on IE, on IE any text in child elements does not look smooth: Page on IE: http://img339.imageshack.us/img339/5572/webpageie.jpg[^] Same page on Google Chrome: http://img839.imageshack.us/img839/985/webpagechrome.jpg[^] Is there any way of making the text in the child elements appear normal in IE?

                    In the end we're all just the same

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #11

                    Browsers do not render all content exactly the same. But using a reset.css such as via here http://meyerweb.com/eric/tools/css/reset/[^] does help.

                    D 1 Reply Last reply
                    0
                    • L Lost User

                      Browsers do not render all content exactly the same. But using a reset.css such as via here http://meyerweb.com/eric/tools/css/reset/[^] does help.

                      D Offline
                      D Offline
                      Dave McCool
                      wrote on last edited by
                      #12

                      I already use a reset CSS, but thanks

                      In the end we're all just the same

                      1 Reply Last reply
                      0
                      • D dawmail333

                        Using proprietary filters in IE generally causes strange side effects. All I can say: http://dowebsitesneedtolookexactlythesameineverybrowser.com/ ;P

                        Posted from SPARTA!!!!!!!!!! 2.0. Don't forget to rate my post if it helped! ;)

                        D Offline
                        D Offline
                        Dave McCool
                        wrote on last edited by
                        #13

                        However, IE being the default broswer that a lot use, I would like the transparacy to work well in it, I use google analytics and more people view my current site in IE than in other browsers, and if the text doesn't look smooth and normal on it, its not really going to help much, its not so much important that the website doesn't look 100% in other browsers as I can say this on my home page.

                        In the end we're all just the same

                        D 1 Reply Last reply
                        0
                        • D Dave McCool

                          However, IE being the default broswer that a lot use, I would like the transparacy to work well in it, I use google analytics and more people view my current site in IE than in other browsers, and if the text doesn't look smooth and normal on it, its not really going to help much, its not so much important that the website doesn't look 100% in other browsers as I can say this on my home page.

                          In the end we're all just the same

                          D Offline
                          D Offline
                          dawmail333
                          wrote on last edited by
                          #14

                          All I can say mate, is good luck. IE is a bitch to design for. End of story. Until IE9 is mainstream, IE is going to be the most hated browser for web designers. Trust me, not-so-smooth text seriously is the least of your worries. People aren't going to immediately leave because of it.

                          Posted from SPARTA!!!!!!!!!! 2.0. Don't forget to rate my post if it helped! ;)

                          D 1 Reply Last reply
                          0
                          • D dawmail333

                            All I can say mate, is good luck. IE is a bitch to design for. End of story. Until IE9 is mainstream, IE is going to be the most hated browser for web designers. Trust me, not-so-smooth text seriously is the least of your worries. People aren't going to immediately leave because of it.

                            Posted from SPARTA!!!!!!!!!! 2.0. Don't forget to rate my post if it helped! ;)

                            D Offline
                            D Offline
                            Dave McCool
                            wrote on last edited by
                            #15

                            Thanks, your right. I'll see what I can do, I know IE is annoying. Its just that the tex seems harder to read this way and if people find the text a bit hard to read, they won't stay long. I'll see what I can do.

                            In the end we're all just the same

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups