Rails 3: Access to twitter bootstrap variables + mixins without importing it

后端 未结 2 675
灰色年华
灰色年华 2021-02-15 15:12

I\'m using Rails 3 for the first time (especially asset pipelining and less-rails-bootstrap), so I might be missing some really basic concept here. I\'ve tried two approaches fo

相关标签:
2条回答
  • 2021-02-15 15:59

    Your answer is sufficient if you want to exclusively use the default twitter bootstrap variables. If you find yourself wanting to override the variables and have them applied to BOTH twitter bootstrap's styles AND your own styles, you'll need to do separate out your variables into its own myvariables.less file and have that file included with twitter bootstrap instead of in the manifest.

    Example

    application.css:

    /*
     * Notice we aren't including twitter/bootstrap/bootstrap in here
     *= require bootstrap_and_overrides
     *= require mystyles
     */
    

    bootstrap_and_overrides.less:

    # Bootstrap with both bootstrap's variables, and your own
    @import "twitter/bootstrap/bootstrap";
    @import "myvariables";
    

    mystyles.less:

    # Your styles with both bootstrap's variables, and your own
    @import "myvariables";
    h1 {
      // Use 
      color: @textColor;
    }
    

    myvariables.less:

    @import "twitter/bootstrap/variables";
    @textColor: green;
    
    0 讨论(0)
  • 2021-02-15 16:07

    I figured out a possible way to do this without leading to (too much) repetition of CSS code.

    application.css

    /*
     *= require twitter/bootstrap
     *= require mystyles
     */
    

    mystyles.css

    @import "twitter/bootstrap/variables.less";
    @import "twitter/bootstrap/mixins.less";
    /* My styles come here, which use variables & mixins defined in twitter bootstrap code */
    
    0 讨论(0)
提交回复
热议问题