Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda