透明元素内部不透明

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了透明元素内部不透明相关的知识,希望对你有一定的参考价值。

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!
  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>

以上是关于透明元素内部不透明的主要内容,如果未能解决你的问题,请参考以下文章

CSS实现父元素半透明,子元素不透明

CSS实现父元素半透明,子元素不透明

CSS实现父元素半透明,子元素不透明

CSS实现父元素半透明,子元素不透明

css怎样仅设置div元素背景透明度,而不设置div元素里面元素的透明度

QML 不透明度继承