box-shadow on top of children

后端 未结 3 535
独厮守ぢ
独厮守ぢ 2020-12-25 11:18

How do I get an inset CSS3 box-shadow to render on top of its children elements?

Problem:

HTML:

3条回答
  •  北海茫月
    2020-12-25 12:05

    cant be done directly from css.. (it is not shadow if it goes above overlapping elements)

    you would need to rework your html a bit by adding a div (or use a pseudo element as suggested by miguelcobain's answer) to overlay the shadow and your CSS to make the new div have the shadow..

    #chatroom {
      border: 1px solid #CCC;
      height: 135px;
      font-size: 0.75em;
      line-height: 1.2em;
      overflow: auto;
      position: relative;
    }
    
    .shadow {
      position: absolute;
      left: 0px;
      top: 0px;
      right: 0px;
      bottom: 0px;
      -moz-box-shadow: inset 0 0px 4px rgba(0, 0, 0, .55);
      -webkit-box-shadow: inset 0 0px 4px rgba(0, 0, 0, .55);
      box-shadow: inset 0 0px 4px rgba(0, 0, 0, .55);
    }
    
    .chatmessage {
      padding: 4px 2px;
    }
    
    .chatmessage b {
      margin-right: 2px;
    }
    
    .chatmessage:nth-child(2n) {
      background: #EEE;
    }
    User 1:Test
    User 2:Test
    User 1:Test
    User 2:Test

提交回复
热议问题