简体   繁体   English

样式组件 + SCSS

[英]Styled-components + SCSS

I need implement dynamic line-clamp, depending on container height.我需要根据容器高度实现动态线夹。 The solution I want to implement is:我要实施的解决方案是:

const Component = styled.div`
@use 'sass:math';

  display: -webkit-box;
  -webkit-line-clamp: floor(calc(100% / 20));
  -webkit-box-orient: vertical;
  overflow: hidden;
  max-height: 100%;
`

but inspector indicates floor(calc(100% / 20));但检查员指出floor(calc(100% / 20)); as invalid property.作为无效财产。

Do you have any ideas how to make this work?你有什么想法如何使这项工作?

I think you should invert the functions (calc and floor) order.我认为您应该反转函数(calc 和 floor)的顺序。 Because calc(100% / 20) doesn't return a number and the function floor requires a number as parameter.因为calc(100% / 20)不返回数字并且函数 floor 需要一个数字作为参数。

 body {
      @use 'sass:math';
      display: -webkit-box;
      -webkit-line-clamp: calc(floor(100% / 20));
      -webkit-box-orient: vertical;
      overflow: hidden;
      max-height: 100%;
    }

I tested it in a live SASS editor, check it out: https://www.sassmeister.com/gist/24b2639cd1680c0ceceb37f910654efe我在实时 SASS 编辑器中对其进行了测试,请查看: https : //www.sassmeister.com/gist/24b2639cd1680c0ceceb37f910654efe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM