How to apply an opacity without affecting a child element with html/css?

前端 未结 12 2356
臣服心动
臣服心动 2020-11-29 04:12

I want to achieve this using html and css:

\"schema\"

I have tried to set the opacity of the container

12条回答
  •  一个人的身影
    2020-11-29 04:24

    As far as I know you can't do it in a simple way. There a couple of options here:

    1. Use absolute positioning to position box "inside" the container.

      #container {
          opacity: 0.3;
          background-color: #777788;
          position: absolute;
          top: 100px;
          left: 100px;
          height: 150px;
          width: 300px;
      }
      #box {
          opacity: 1;
          background-color: #ffffff;
          position: absolute;
          top: 110px;
          left: 110px;
          height: 130px;
          width: 270px;
      }

      Something in here

    2. Use Javascript - almost the same as above, but position and size don't have to be hardcoded.

提交回复
热议问题