CSS3 Box shadow size – percent units?

后端 未结 5 1401
日久生厌
日久生厌 2021-02-01 13:46

I\'m working on a project that needs to use CSS3 box-shadow property. That\'s fine, but I have found out that spread size of shadow can\'t be set to a percentage of parent objec

5条回答
  •  既然无缘
    2021-02-01 14:08

    If the element has a defined width (except for a percentage width), you can create a custom property for the width and then use the custom property with the calc() function for box shadow.

    For example, the CSS code below makes the "spread radius" of box shadow 20% of the div's width:

    div {
        --width: 100px;
        width: var(--width);
        box-shadow: 0 0 0 calc(var(--width) * 0.2) #aaa;
    }
    

提交回复
热议问题