将 border-radius 应用于 box-shadow 但不应用于 div 本身

Aus*_*tin 2 html css border

我想将边框半径应用于 abox-shadow而不是 div 本身,因此最终结果将是左侧带有 90 度角 div 的圆形框阴影。

.div-to-style {
    -webkit-box-shadow: -20px 0px 0px 0px blue;
    -moz-box-shadow: -20px 0px 0px 0px blue;
    box-shadow: -20px 0px 0px 0px blue;
    border-radius: 8px 8px 8px 8px;

    background-color: red;
    width: 200px;
    height: 50px;
    margin-left:40px;
}
Run Code Online (Sandbox Code Playgroud)
<div class="div-to-style">
</div>

<p>
Want the red section to have a straight border on the left
</p>
Run Code Online (Sandbox Code Playgroud)

https://jsfiddle.net/alair016/vdcohttk/

此 CSS 的问题在于, 应用于border-radius以及box-shadow左侧的 div。

Pau*_*e_D 5

盒子阴影不是一个元素。您无法将 border-radius 添加到效果中。

尝试使用伪元素:

.div-to-style {
  border-radius: 0 8px 8px 0;
  background-color: red;
  width: 200px;
  height: 50px;
  margin-left: 40px;
  position: relative;
}
.div-to-style::before {
  content: '';
  position: absolute;
  left: -20px;
  width: 20px;
  height: 100%;
  background: blue;
  z-index: -1;
  border-radius: 8px 0 0 8px;
}
Run Code Online (Sandbox Code Playgroud)
<div class="div-to-style">
</div>
Run Code Online (Sandbox Code Playgroud)

奖励选项:无伪元素 - 渐变背景

.div-to-style {
  border-radius: 8px;
  background: linear-gradient(to right, blue, blue 20px, red 20px);
  width: 200px;
  padding-left: 20px;
  height: 50px;
  margin-left: 40px;
  position: relative;
}
Run Code Online (Sandbox Code Playgroud)
<div class="div-to-style">
</div>
Run Code Online (Sandbox Code Playgroud)