CSS box shadow around triangle

前端 未结 6 946
自闭症患者
自闭症患者 2021-01-11 13:25

I need to create a triangle with a drop shadow using simple html and css. Answered by another stackoverflow question, I was able to create the triangle with mitered borders

6条回答
  •  南笙
    南笙 (楼主)
    2021-01-11 13:52

    You can use the "transform" property to rotate a square 45 degrees and hide half of it, but not all browsers support it, so you'll need a fallback.

    .triangle-with-shadow {
       width: 100px;
       height: 50px;
       position: relative;
       overflow: hidden;
       box-shadow: 0 16px 10px -15px rgba(0,0,0,0.5);
    }
    .triangle-with-shadow:after {
       content: "";
       position: absolute;
       width: 50px;
       height: 50px;
       background: #999;
       transform: rotate(45deg);
       -ms-transform:rotate(45deg); /* IE 9 */
       -moz-transform:rotate(45deg); /* Firefox */
       -webkit-transform:rotate(45deg); /* Safari and Chrome */
       -o-transform:rotate(45deg); /* Opera */
       top: 25px;
       left: 25px;
       box-shadow: -1px -1px 10px 0px rgba(0,0,0,0.5);
    }​
    

    Demo on jsfiddle.

    Lifted from this CSS Tricks page with modifications.

提交回复
热议问题