0

I have a design requirement where a div has to overlap another div, but the text within the inner div needs to be visible.

<div class='box1'>
  <div class='sendAbove'>
    This is a message I want to be visible in this div
  </div>
</div>

<div class='box2'>

</div>

CSS

.box1 {
  width: 100px;
  height: 100px;
  position: absolute;
  top: 20px;
  left: 20px;
  background: white;
  border: solid red 1px;
  z-index: 3;
}

.box2 {
  width: 100px;
  height: 100px;
  position: absolute;
  top: 50px;
  left: 50px;
  background: white;
  border: solid blue 1px;
  z-index: 4;
}

.sendAbove {
  z-index: 5;
}

https://jsfiddle.net/sriv87/Lcoxrgpw/9/

Edit: Updated fiddle https://jsfiddle.net/sriv87/c8eh5fcs/

Expected result

nonexistent myth
  • 135
  • 1
  • 14

3 Answers3

1

Ok, Edited as per your updated requirement. Check this.

.callout {
  position: relative;
  background: #ffffff;
  border: 1px solid #f00;
  width: 200px;
}

.callout:after,
.callout:before {
  position: absolute;
  left: 100%;
  top: 50%;
  border: solid transparent;
  content: " ";
  height: 0;
  width: 0;
}

.callout:after {
  border-color: rgba(255, 255, 255, 0);
  border-left-color: white;
  border-width: 10px;
  margin-top: -10px;
}

.callout:before {
  border-color: rgba(255, 0, 0, 0);
  border-left-color: #f00;
  border-width: 11px;
  margin-top: -11px;
}
<div class="callout">
  <p>Message here</p>
</div>
Sujan Sundareswaran
  • 2,324
  • 2
  • 11
  • 25
0

With your current layout it wont work. Because the parent of .sendAbove is absolute positioned, its html will allways be part of its parent. Regardless you make it absolute or relative.

So to make this workable, you should put the .sendAbove outside .box1. Give them both the same position, height and width.

.wrapper {
  position: relative;  
}

.box1, .sendAbove {
  position: absolute;
  top: 20px;
  left: 20px;
  width: 100px;
  height: 100px;
}

.box1 {
  background: white;
  border: solid red 1px;
  z-index: 3;
}

.box2 {
  width: 100px;
  height: 100px;
  position: absolute;
  top: 50px;
  left: 50px;
  background: white;
  border: solid blue 1px;
  z-index: 4;
}

.sendAbove {
  z-index: 5;
}
<div class="wrapper">
<div class='box1'>
</div>

<div class='sendAbove'>
    This is a message I want to be visible in this div
  </div>

<div class='box2'>

</div>
</div>
Red
  • 6,599
  • 9
  • 43
  • 85
  • the message is dynamic. The width and the height would vary for me to set the border. I have updated the question to give you a better idea. – nonexistent myth Mar 05 '18 at 08:49
0

Just change the background color settings in .box2 and that will make text underneath visible. How visible will be decided by the 'a' in rgba, and runs from 0 to 1, ie, 0.1 is very transparent, 0.9 has virtually no transparency.

 .box2 {
      width: 100px;
      height: 100px;
      position: absolute;
      top: 50px;
      left: 50px;
      **background-color: rgba(255,255,255,0);**
      border: solid blue 1px;
      z-index: 4;

}

nooby
  • 87
  • 7