Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!