How do you strip the unit from any number in SASS?

后端 未结 2 1447
攒了一身酷
攒了一身酷 2020-12-02 16:40

I know you can strip units from numbers in SASS when you know the unit before-hand like this:

$number: 16px;
$without-unit: 16px / 1px;
@warn $without-unit;          


        
2条回答
  •  孤街浪徒
    2020-12-02 17:37

    I think you'd have to add a custom Ruby function to strip the units (see the documentation on adding custom functions). It would look something like this, I think (warning, untested):

    module Sass::Script::Functions
      def strip_units(num)
        assert_type num, :Number
        Sass::Script::Number.new(num.value)
      end
    end
    

提交回复
热议问题