Can I override global variables from the calling s

2019-07-21 20:52发布

问题:

I need to override some global variables used within a mixin. However I'm reluctant to just change the variables in global space (wouldn't be overriding then)

Consider this given mixin with the required variable defined.

// Mixin and adjust the regular image class
.thumbnail {
  display: block;
  padding: @thumbnail-padding;
  margin-bottom: @line-height-computed;
  line-height: @line-height-base;
  background-color: @thumbnail-bg;
  border: 1px solid @thumbnail-border;
  border-radius: @thumbnail-border-radius;
  .transition(all .2s ease-in-out);

  > img,
  a > img {
    .img-responsive();
    margin-left: auto;
    margin-right: auto;
  }

  // Add a hover state for linked versions only
  a&:hover,
  a&:focus,
  a&.active {
    border-color: @link-color;
  }

  // Image captions
  .caption {
    padding: @thumbnail-caption-padding;
    color: @thumbnail-caption-color;
  }
}

Yep, from Bootstrap... Now I want that mixin to work with different variables, without changing the global scoped ones. Can this be done?

article.publications {
  .news-thumb {
    @thumbnail-padding: 10px;
    @line-height-computed: 20px;
    @line-height-base: 30px;
    @thumbnail-bg : black;
    .thumbnail();
  }
}
标签: less