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

185
Visualizações
Make any part of a child DIV opaque if it is outside of the area of the parent DIV without overflow:hidden

I have a div inside of another div and the inner div can be sized up by the user.

Currently if they size it up then it covers over the outer div completely unless I use overflow:hidden but then they can't see the outer edges of the inner div anymore.

Ideally I would like, if the innerdiv reaches outside the boundary of the parent outerdiv, I would like anything outside of said boundary to look different, ideally just an opacity setting.

Basically I am looking for something like

overflow:opacity .3;

Currently I just have a hidden or not-hidden setting that is toggled, but it isn't ideal.

This is what it would look like with the innerdiv set to the color red. Any part of that innerdiv that is outside of the outerdiv is opaque. (The pink & red element is the same div. The full red part is the boundary of the parent/outer div.)

enter image description here

I have an un-working example below.

I am open to other ways of setting this up, but if it can be done with the configuration below it would be ideal.

I am fine doing this with javascript/jQuery as well.

.frame {
  width:200px;
  height:200px;
  margin-left:auto;
  margin-right:auto;
  display;block;

  margin-top:30px;
  
}


.outerdiv {
width:200px;
height:200px;
 background:gray;
 border:solid 1px #C0C0C0;
}



.innerdiv {
  width:240px;
  height:240px;
  position:absolute;
  background:red;
  margin-left:-20px;
  margin-top:-20px;
  opacity:.2
  
}
<div class="frame">
<div class="outerdiv">
<div class="innerdiv">

</div>
</div>
</div>

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

0

Because the innerdiv has an absolute position, it goes outside the outer div. If the outer div had a relative position, then the inner div can not go outside of it.

about 4 years ago · Juan Pablo Isaza Relatório

0

You could play around with mix-blend-mode, with the frame being bigger and with a white background.

To illustrate the idea, this rather simple snippet uses a mix-blend-mode of difference on the inner element which blends with the white background of the frame to give a sort of cyan and with the black of the outer to give the actual red.

There are several different combinations possible with mix-blend-mode. (I confess I've never found a good way of knowing exactly what effect each one will have in advance and always end up experimenting).

.frame {
  width: 100vw;
  height: 100vh;
  margin-left: auto;
  margin-right: auto;
  display: inline-block;
  margin-top: 30px;
  position: relative;
  background: white;
}

.outerdiv {
  width: 200px;
  height: 200px;
  background: black;
  border: solid 1px #C0C0C0;
  margin-top: 20px;
  margin-left: 20px;
}

.innerdiv {
  width: 240px;
  height: 240px;
  position: absolute;
  background: red;
  margin-left: -20px;
  margin-top: -20px;
  mix-blend-mode: difference;
}
<div class="frame">
  <div class="outerdiv">
    <div class="innerdiv">

    </div>
  </div>
</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