Search code examples
cssoutline

stop child covering parent outline?


Due to some elements being inside a slideshow i'm using outline with negative offset instead of border.

However the child elements are covering the outline but i want the border over them. I'm using it to frame the content.

http://jsfiddle.net/z22kw2zq/1/

.parent {
 position:relative; outline: green 3px solid;
  outline-offset:0px;
background-color:pink;
pading:5px;
overflow:hidden;
}
.child {position:relative; top:26px; background-color:yellow;
display:inline;
}

Solution

  • You could use :after pseudo-element for outline and add position: absolute.

    .parent {
      position: relative;
      background-color: pink;
      overflow: hidden;
    }
    .parent:after {
      width: 100%;
      height: 100%;
      content: '';
      outline: green 3px solid;
      outline-offset: -3px;
      position: absolute;
      top: 0;
      left: 0;
    }
    .child {
      position: relative;
      top: 23px;
      background-color: yellow;
      display: inline;
    }
    p {
      margin: 0;
    }
    <div class="parent">
      <div class="child">lorem ipsum doler sit amet</div>
      <p>text here</p>
    </div>