transparent background image

后端 未结 5 1683
暗喜
暗喜 2020-12-31 04:05

I have the following css.

   #mypass{
                background-image: url(\"Images/logo.png\");
                background-attachment: fixed;
                      


        
相关标签:
5条回答
  • 2020-12-31 04:47

    The element that needs to have semi-transparent background:

    #myPass
    

    This is how without touching the HTML, we add controllable transparency background to the element:

    #myPass::before {
        content: "";
        position: absolute;
        top: 0; right: 0;
        bottom: 0: left: 0;
        background: url(image.jpg) no-repeat top center;
        opacity: 0.5;
    }
    

    The only thing to note is that the #myPass element, must be positioned:

    #myPass {
        position: relative; /* absolute is good too */
    }
    
    0 讨论(0)
  • 2020-12-31 04:50

    Just ran into this issue myself. If you combine linear-gradient with the background image url, you can control image opacity. By keeping the two "gradients" the same, you can get a filter/opacity effect without using opacity proper.

    i.e.

     .bg-image {
            background: linear-gradient(rgba(255,255,255,0.5), rgba(255,255,255,0.5)), url(path-to-image.jpg) center no-repeat;
            background-size: cover;
          }
    
    0 讨论(0)
  • 2020-12-31 04:53

    Why don't you create another div and use it as a pseudo-background or something?

    0 讨论(0)
  • 2020-12-31 05:05

    This is the way to do it:

    div {
      width: 200px;
      height: 200px;
      display: block;
      position: relative;
    }
    
    div::after {
      content: "";
      background: url(image.jpg);
      opacity: 0.5;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      position: absolute;
      z-index: -1;   
    }
    
    0 讨论(0)
  • 2020-12-31 05:06

    You can't adjust the translucency of a background image with CSS.

    You can adjust the translucency of an entire element (opacity) or of a plain background rgba(), but not a background image.

    Use an image format that supports translucency natively (such as PNG) and embed the translucency you want in the image itself.

    0 讨论(0)
提交回复
热议问题