Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

149
Visualizações
Adding a semi-transparent, solid bg color over a jpeg

I have an <img> tag that I am using as a background image, but I want to have a semi-transparent, solid background color, that still shows the original image, at the same ratio and size, under the background color. Here is some of my code (if you need any more info, please ask. Also, the JS and CSS is all inline, and I use jQuery 3.6.0):

<div class="home-screen">
  <img class="background" alt="Background Image" src="./assets/images/Desktop_Pictures/Catalina-min.jpg" />
</div>
div.home-screen {
  height: 100%;
  overflow: hidden;
}

div.home-screen img.background {
  top: -50%;
  margin-left: 0;
  transform: translateX(0);
  width: 100%;
  position: fixed;
}
var isLaunchpadOpen = false;

function openLaunchpad() {
        if (isLaunchpadOpen == false) {
          $("div.home-screen")
            .css("background-color", "rgb(211, 211, 211)")
            .css("background-origin", "content-box")
            .css("top", 0)
            .css("position", "fixed");

          $("div.home-screen img.background")
            .css("background-blend-mode", "multiply")
            .css("filter", "opacity(50%)");

          isLaunchpadOpen = true;
        } else if (isLaunchpadOpen == true) {
          $("div.home-screen img.background")
            .css("background-color", "none")
            .css("filter", "opacity(100%)")
            .css("background-blend-mode", "normal");

          isLaunchpadOpen = false;
        }
      }

Note, this is not all the code, this is only the code that I assume is causing the problem

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can use the CSS filter property opacity

img {
 filter:opacity(50%);
}

in this case i recommend you use the css filter property if you want to know more about the css filter property i recommend you check this examples:

I hope I've helped ;) css filter property

about 4 years ago · Juan Pablo Isaza Relatório

0

  1. Apply position: relative; to the wrapper of the image: .home-screen { psotion: relative; }
  2. Create a pseude-element with ::after that spans the entire wrapper: .home-screen::after { display: block; content: ""; position: absolute; inset: 0;
  3. Apply a semi-transparent background-color to the pseudo-element by using a rgba color as value.

.home-screen {
  position: relative;
}

.home-screen::after {
  content: "";
  display: block;
  position: absolute;
  inset: 0;
  background-color: rgba(0, 0, 255, 0.5);
}

/* for styling purpose only */
img {
  width: 100%;
}
<div class="home-screen">
  <img class="background" alt="Background Image" src="https://www.tacoshy.de/Images/Yoshi/IMAG0735.jpg" />
</div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda