Non-Transparent Inside Transparent Elements

If using transparency on a block element it makes the text inside transparent as well. Is there a way you can prevent that from happening? Yes, you may do it by putting the text in another div and setting the opacity to 100%, but that didn't do the job. Although, logically, it would!

[View All Snippets]
Show Plain Text »
  1. <style type="text/css">
  2. .bar {
  3.    height: 4em;
  4.    padding-top: 2em;
  5.    opacity: 0.5;
  6.    background: black;
  7.    border-top: 3px solid #ccc;
  8.    border-bottom: 3px solid #ccc;
  9.    margin-top: 5.0em;
  10. }
  11. h2.ontop {
  12.    position: relative;
  13.    top: 4.7em;
  14. }
  15. </style>
  16.  
  17. <div class="bar">
  18.    <h2>Text in this bar inherits the transparency.</h2>
  19. </div>
  20.        
  21. <h2 class="ontop">Text in this bar stays opaque.</h2>
  22. <div class="bar"></div>


Result:

Text in this bar inherits the transparency.

Text in this bar stays opaque.

Create Your Free Account
Please remember that this information is essential to use our services correctly.
After creating the account you will be able to download all of our FREE products.
Fields marked with * are mandatory






Please send me information about updates, new products, specials and discounts from ApPHP!
We recommend that your password should be at least 6 characters long and should be different from your username/email. Please use only letters of the English alphabet to enter your name.

Your e-mail address must be valid. We use e-mail for communication purposes (order notifications, etc). Therefore, it is essential to provide a valid e-mail address to be able to use our services correctly.

All your private data is confidential. We will never sell, exchange or market it in any way. Please refer to Privacy Policy.

By clicking "Create Account", you are indicating that you have read and agree to the ApPHP Terms & Conditions.

Quick Registration with: Facebook / Google