html - 倾斜边框上的框阴影 :after pseudoelement

标签 html css sass

所以,我一直在寻找解决方案,但没有成功。我需要父 div 上的 box-shadow 来传递 :after 伪元素。

目前,框阴影仍然像矩形一样应用,而不是跟随边框的边缘,这会在 div 的末端呈现 Angular 。你可以在这里看到我在说什么:

https://codepen.io/thomasjost/pen/XBOjqm

这是我的 HTML:

<div class="total-tag">
  <h3 class="h-big-dollar-sign">$</h3>
  <h1 class="total">13,550</h1>
</div>

SCSS:

.total-tag {
    border-radius     : 6px 0 0 6px;
    background        : #EBEDEE;
    height            : 68px;
    width             : 15em;
    position          : relative;
    box-shadow: 0 1px 2px 0 rgb(0,0,0);
    display: flex;
    justify-content: flex-start;
    align-content: center;
    align-items: center;


    &:after {
            content                 : '';
            display                 : block;
            position                : absolute;
      top                           : 0;
      left            : 15em;
            border-style        : solid;
            border-color        : #EBEDEE transparent transparent transparent;
      border-width    : 68px 34px 0 0;
    box-shadow: 1px 1px 2px 0 rgb(0,0,0);
    }

  }


 .total {
    font-size: 38px;
    font-weight: 300;
    color: #64A31B;
    line-height: 1em;
    margin-top: 5px;
  }
  .h-big-dollar-sign {
    position: relative;
    left: inherit;
    top: inherit;
    margin-top: 5px;
    margin-left: 17px;
    font-size: 24px;
  }

如有任何帮助,我们将不胜感激。

最佳答案

你可以使用渐变背景来绘制背景并模拟阴影:

 &:after {
            content                 : '';
            display                 : block;
            position                : absolute;
      top                           : 0;
      left            : calc(15em - 2px);/* minus shadow's width */
      bottom          : 0;
      width           :36px;
      background: linear-gradient(to bottom right, #EBEDEE 49%, #000  50%, transparent calc(50% + 2px)  );/* draw bg and part of slanted shadow */
      box-shadow:0px -2px 2px -3px;/* top shadow is to be shawn too, give it a try */
    }

演示:

.total-tag {
  border-radius: 6px 0 0 6px;
  background: #EBEDEE;
  height: 68px;
  width: 15em;
  position: relative;
  box-shadow: 0 1px 2px 0 black;
  display: flex;
  justify-content: flex-start;
  align-content: center;
  align-items: center;
}
.total-tag:after {
  content: '';
  display: block;
  position: absolute;
  top: 0;
  left: calc(15em - 2px);
  bottom: 0;
  width: 36px;
  background: linear-gradient(to bottom right, #EBEDEE 49%, #000 50%, transparent calc(50% + 2px));
  box-shadow: 0px -2px 2px -3px;
}

.total {
  font-size: 38px;
  font-weight: 300;
  color: #64A31B;
  line-height: 1em;
  margin-top: 5px;
}

.h-big-dollar-sign {
  position: relative;
  left: inherit;
  top: inherit;
  margin-top: 5px;
  margin-left: 17px;
  font-size: 24px;
}
<div class="total-tag">
  <h3 class="h-big-dollar-sign">$</h3>
  <h1 class="total">13,550</h1>
</div>

关于html - 倾斜边框上的框阴影 :after pseudoelement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51794945/

相关文章:

JavaScript 像 jQuery 一样使用 prevAll?

javascript - 在进行 JQuery 对话框选择之前,HTML 表单继续提交?

html - div 内垂直居中

html - 在 Sass 中,我们如何根据宽度值分配高度?

java - 使用 servlet 维护 <select> 语句的持久状态

javascript - 更改文件不起作用?

css - 编程语言的图标字体

javascript - 如何通过在输入字段中输入十六进制颜色(使用或不使用 jQuery)来更改所需 div 的背景颜色?

css - IE11 消息栏从底部飞起而不是从顶部缓入

ruby - Padrino 没有看到 SCSS