Question about how a element's opacity affecting its children.

Dear All,

I have a question about how a element's opacity affecting its children. I think the parent element's opacity shall cascade to its childen elements, for example:

"

<div id="parent" style:position="absolute" style:x="10px" style:y="10px" style:width="100px" style:height="100px" style:opacity="0.2">

<button id="children"
style:position="absolute"
style:x="5px" style:y="5px"
style:width="50px" style:height="50px"
style:opacity="0.8" />

</div>

"

I think button "children" shall be drawned as a half-transparent element with opacity=0.2*0.8=0.16, but I am not sure, so can someone tell me the right way to deal with such issue

Thank you!

Best Regards,
Rekan.



Answer this question

Question about how a element's opacity affecting its children.

  • qwv

    The spec has been clarified that the opacity of a parent element does not affect its children, unless it is zero in which case none of the children will draw.

  • VenkateshMD

    In the short term, I would recommend not relying on current iHDSim behaviour. I would also recommend not setting opacity on any elements that have children (eg a <div> with some child buttons). If you want the background of the div to be transparent, I would recommend using another child div for that... for example, instead of:

    <div opacity="0.5" backgroundImage="something" />
    <button />
    <button />
    </div>

    I would suggest doing:

    <div>
    <div opacity="0.5" backgroundImage="something" />
    <button />
    <button />
    </div>

    This will ensure that the appearance of your markup is independent of whether opacity multiplies or not. This should only be a short-term solution until the spec is clarified.



  • maryz

    May I ask why

    The HDDVD spec did not clearly define how opacity works for overlapped elements.
    But if we follow the opacity in CSS3 and modern browser implementations,
    you will find that the opacity is multiplied as 0.2*0.8 = 0.16

  • Mateusz Rajca

    Please look at it this way that div is drawn on body with opacity 0.2 and button is drawn on div with opacity 0.8.


  • Question about how a element's opacity affecting its children.