【问题标题】:Adding a LESS Bootstrap mixin to the body with a background image将 LESS Bootstrap mixin 添加到带有背景图像的主体
【发布时间】:2017-01-28 10:00:23
【问题描述】:

我正在尝试使用带有渐变 LESS Bootstrap 混合的背景图像,但它不起作用,我已将所有 Bootstrap .less 文件导入到 style.less 文件中,其中导入了我的 theme.less (这个文件)。每当我执行以下 grunt 任务运行程序时,都不会编译 theme.less 文件。我有这个代码:

@base-url: '../img/backgrounds';

body {
  background: #gradient.directional(#333; #000; 45deg), url('@{base-url}/bus.jpg'), no-repeat center center fixed; /* fallback */
  background-size: cover;
  overflow-x: hidden;
}

我也试过了:

@base-url: '../img/backgrounds';

body {
  #gradient.directional(#333; #000; 45deg), url('@{base-url}/bus.jpg'), no-repeat center center fixed; /* fallback */
  background-size: cover;
  overflow-x: hidden;
}

在第二个示例中,编译器说我在第 9 行第 49 列中缺少一个 ')'

【问题讨论】:

    标签: css twitter-bootstrap twitter-bootstrap-3 less


    【解决方案1】:

    我现在明白了,我需要做的就是修改“bootstrap/mixins/gradients”文件夹中的引导渐变混合文件,我更改了混合的名称并使用背景图像做了我自己的。像这样:

    mymixins.less 文件:

    @base-url: '../img/backgrounds';
    
    #gradient1 {
        .directional1(@start-color: rgba(255,255,255, 1); @end-color: rgba(0,0,0,1); @deg: 45deg) {
            background-repeat: repeat-x;
            background: -webkit-linear-gradient(@deg, @start-color, @end-color),url('@{base-url}/bus.jpg'), no-repeat center center fixed;  // Safari 5.1-6, Chrome 10+
            background: -o-linear-gradient(@deg, @start-color, @end-color), url('@{base-url}/bus.jpg'), no-repeat center center fixed; // Opera 12
            background: linear-gradient(@deg, @start-color, @end-color), url('@{base-url}/bus.jpg'), no-repeat center center fixed; // Standard, IE10, Firefox 16+, Opera 12.10+, Safari 7+, Chrome 26+
        }
    }
    

    我的 theme.less 文件:

    .background {
        #gradient1.directional1(rgba(255,255,255,0.3); rgba(0,0,0,0.3); 45deg);
        background-size: cover;
        overflow-x: hidden;
    }
    

    【讨论】:

    • 假设您希望 no-repeat center center fixed 应用于 url('@{base-url}/bus.jpg'),则不应使用逗号分隔它们。逗号用于定义多个背景(如渐变背景和图像背景之间的逗号)
    猜你喜欢
    • 1970-01-01
    • 2012-07-03
    • 2011-09-14
    • 1970-01-01
    • 2017-04-17
    • 2015-11-06
    • 2012-04-09
    • 2011-06-01
    • 2017-01-14
    相关资源
    最近更新 更多