How do you set CSS properties as mixin values in SASS using string interpolation?

Patricia Arquette
Release: 2024-10-29 21:52:29
Original
664 people have browsed it

How do you set CSS properties as mixin values in SASS using string interpolation?

Setting SASS Mixin Values to CSS Properties

When creating universal margin/padding mixins, it may be necessary to set CSS properties as mixin values. To achieve this, string interpolation is employed.

String Interpolation for CSS Properties

To use variables as CSS property names, string interpolation (#{$var}) is required.

Example

The following mixin demonstrates how to set CSS properties using string interpolation:

<code class="scss">[class*="shift"] {
  $sft-o: 10px;
  @mixin shift_stp($val) {
    &[class*="_sml"]{ #{$val}: $sft-o; }
    &[class*="_mid"]{ #{$val}: $sft-o * 2; }
    &[class*="_big"]{ #{$val}: $sft-o * 3; }
  }
  &[class*="_m"]{
    @include shift_stp(margin);
  }
  &[class*="_p"]{
    @include shift_stp(padding);
  }
}</code>
Copy after login

Note

When using attribute selectors (*="_m"), it's important to consider the potential conflicts with other classes that contain "_mid" within their names.

The above is the detailed content of How do you set CSS properties as mixin values in SASS using string interpolation?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!