Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS [Solved] Problem with CSS Opacity

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #30012
    telters
    Member

    HI there

    So, I am creating a website, and I want the bg of the div to have an opacity of 0.6 (as you can see here), but it than makes my text that ‘translucent’ as well. Here is the HTML code:



    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.



    Here is the CSS

    #content1 {
    opacity:0.6;
    width:425px;
    overflow:auto;
    float:left;
    padding-left:50px;
    }

    #content1 p {
    padding-top:0px;
    padding-bottom:50px;
    background:#999;
    color:#000;
    opacity:1.0;
    font-family:Tahoma, Geneva, sans-serif;
    }

    How can I make the text have opacity of 1, and the background of the div an opacity of 0.6 without the text becoming that opacity?

    #81687
    TheDoc
    Member

    It can’t be a part of the same div. You’ll need to create a background div (content-bg), and then create a content div (content) on top of it with no background.

    #81681
    telters
    Member

    That would be my problem

    So, now my code looks like this:



    Hi there



    With CSS like this:


    #content-bg {
    opacity:0.6;
    width:425px;
    overflow:auto;
    float:left;
    padding-left:50px;
    background:#999;
    }

    #content1 {
    padding-top:0px;
    padding-bottom:50px;
    color:#000;
    opacity:1.0;
    font-family:Tahoma, Geneva, sans-serif;
    }

    Am I correct?

    #81671
    TheDoc
    Member

    Technically, #content1 is still “inside” #content-bg.

    I should have specified a little more – you’ll have to keep the #content-bg outside of the content. As in, content-bg can’t be wrapping anything.

    Something like…



    ...


    ...


    And then do some positioning trickery.

    If the content-bg opacity is just a solid color, then you can do something much better! You can create a 1x1px square of #999 with .6 opacity, save it as a png-24 and use that as your repeating background. No need to worry about cascading styles!

    #81669
    telters
    Member

    Awesome! There’s my problem!

    I kept trying to wrap content-bg around everything else, which wasn’t working

    Thanks!

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘CSS’ is closed to new topics and replies.