mixins

Less and Bootstrap: how to use a span3 (or spanX [any number]) class as a mixin?

时光毁灭记忆、已成空白 提交于 2019-11-26 14:48:07
问题 Is it possibile to add span3 class in a mixin to avoid putting it in every element in my HTML? Something like: .myclass { .span3; // other rules... } EDIT I apologize I forgot to specify an important detail: span3 is a standard class of Bootstrap. I didn't find its definition in any file of the Bootstrap framework. 回答1: New Answer (requires LESS 1.4.0) What you actually desire is something known as extending in LESS and SASS terminology. For example, you want an HTML element (just an example)

How to define a dynamic mixin or function name in SASS?

我与影子孤独终老i 提交于 2019-11-26 14:30:49
问题 I want to dynamically create mixins in SASS, named after each item in the list, but it doesn't seem to work. I tried this but I get an error: $event-icons: fair, concert, art-show, conference, dance-show, film, party, festival, theatre, launch @each $event-icon in $event-icons @mixin event-icon-#{$event-icon} background-position: -($event-icon-width * $i) 0 Error: Invalid CSS after "": expected expression (e.g. 1px, bold), was "#{$event-icon}" Is this usage not supported by SASS? I couldn't

Mixing in a trait dynamically

ⅰ亾dé卋堺 提交于 2019-11-26 12:21:54
问题 Having a trait trait Persisted { def id: Long } how do I implement a method that accepts an instance of any case class and returns its copy with the trait mixed in? The signature of the method looks like: def toPersisted[T](instance: T, id: Long): T with Persisted 回答1: This can be done with macros (that are officially a part of Scala since 2.10.0-M3). Here's a gist example of what you are looking for. 1) My macro generates a local class that inherits from the provided case class and Persisted

Using variables for CSS properties in Sass

ぐ巨炮叔叔 提交于 2019-11-26 11:09:23
问题 I am writing a @mixin with some math in it that calculates the percentage width of an element, but since it is very useful I would like to use the same function for other properties too, like margins and paddings. Is there a way to pass the property name as an argument to a mixin? @mixin w_fluid($property_name, $w_element,$w_parent:16) { $property_name: percentage(($w_element/$w_parent)); } 回答1: You need to use interpolation (eg. #{$var} ) on your variable in order for Sass to treat it as a

Is it possible to implement mixins in C#?

依然范特西╮ 提交于 2019-11-26 10:17:54
问题 I\'ve heard that it\'s possible with extension methods, but I can\'t quite figure it out myself. I\'d like to see a specific example if possible. Thanks! 回答1: It really depends on what you mean by "mixin" - everyone seems to have a slightly different idea. The kind of mixin I'd like to see (but which isn't available in C#) is making implementation-through-composition simple: public class Mixin : ISomeInterface { private SomeImplementation impl implements ISomeInterface; public void OneMethod(

@import in @if statement in Sass

馋奶兔 提交于 2019-11-26 09:54:37
问题 I want to load only the css needed for the login page for performance. On my other pages I want a grouped css file that will be cached on every page which contain all my css. I have the following files: minifiedcssforloginpage.scss grouped-pages.scss In minifiedcssforloginpage.scss I declare $load-complete-css:false. Afterwards I import myproject.scss which contains all the imports of my modules, layouts, core... In myproject.scss i want to do something like @if $load-complete-css { @import

How to use mixins properly in Javascript

江枫思渺然 提交于 2019-11-26 08:31:11
问题 I am organizing a small enterprise application but would like to be as DRY as possible. As a result, I\'ve been looking at mixin libraries. I came across this library and thought it might be a good option as it allows you to mix in and out at run time. Also, I can just have one base class (BaseView) for instance and just mixin off of that. Questions What are some real application examples of useful Mixins? (pls no more abstract examples) Do I even need to extend classes or can I just use this

Mixins for ES6 classes, transpiled with babel

天涯浪子 提交于 2019-11-26 08:19:54
问题 According to various sources (2ality, esdiscuss) one should be able to add mixins to classes: EDIT discovered that class methods are not enumerable so that cannot work. Edited the code below, but still no joy class CartoonCharacter { constructor(author) { this.author = author; } drawnBy() { console.log(\"drawn by\", this.author); } } // THIS CANNOT WORK // class methods are not enumerable // class Human { // haveFun() { // console.log(\"drinking beer\"); // } // } let Human = Object.create({}

CSS property as SASS mixin value [duplicate]

谁说我不能喝 提交于 2019-11-26 06:49:59
问题 This question already has answers here : Using variables for CSS properties in Sass (2 answers) Closed 3 years ago . I try to build some universal margin/padding mixin... This is my code: [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); } } Something is not right, so I

Dynamic mixin in Scala - is it possible?

余生颓废 提交于 2019-11-26 06:36:31
问题 What I\'d like to achieve is having a proper implementation for def dynamix[A, B](a: A): A with B I may know what B is, but don\'t know what A is (but if B has a self type then I could add some constraints on A). The scala compiler is happy with the above signature, but I could not yet figure out how the implementation would look like - if it is possible at all. Some options that came to my mind: Using reflection/dynamic proxy. Simplest case: A is an interface on Java level + I can