如何将LESS文件与默认的bootstrap less文件组合在一起

时间:2014-11-15 10:48:40

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

我正在尝试从twitter bootstrap LESS创建一个不同的面板,因此我创建了一个新的LESS文件,并将其命名为 panel.less 。但是,twitter bootstrap已经为面板设置了默认的LESS文件,称为 panels.less

如何将它们组合起来以便它也能处理我的文件?(这可能不是正确的单词)

Panel.less

`

.panel-profile .panel-heading {
    position: relative;
}
.panel-profile .panel-heading  h4 {
    margin: 10px 0 20px;
    font-weight: normal;
}
.panel-profile .panel-heading img {
    margin: 0 auto 10px;
    display: block;
    border: 1px solid #ddd;
    background: #fff;
}
@media (min-width:400px) {
    .panel-profile .panel-heading a {
        font-size: .75em;
        float: right;
    }
   .panael-profile .panel-heading {
    margin-bottom: 30px;
    }
  .panel-profile .panel-heading img {
        position: absolute;
        margin: 0;
        display: inline;
        bottom: -25px;
    }
}

`

Bootstrap.less。 - 这是我的版本不是默认版本 `

// Core variables and mixins
@import "variables.less";
@import "mixins.less";

// Reset
@import "normalize.less";
@import "print.less";

// Core CSS
@import "scaffolding.less";
@import "type.less";
@import "grid.less";
@import "forms.less";
@import "buttons.less";

// Components
@import "component-animations.less";
@import "muicons.less";
@import "dropdowns.less";
@import "button-groups.less";
@import "navs.less";
@import "navbar.less";
@import "media.less";
@import "list-group.less";
@import "close.less";
@import "panel.less";

`

Panels.less `     //     //面板     // ------------------------------------------------ -

// Base class
.panel {
  margin-bottom: @line-height-computed;
  background-color: @panel-bg;
  border: 1px solid transparent;
  border-radius: @panel-border-radius;
  .box-shadow(0 1px 1px rgba(0,0,0,.05));
}

// Panel contents
.panel-body {
  padding: @panel-body-padding;
  &:extend(.clearfix all);
}

// Optional heading
.panel-heading {
  padding: 10px 15px;
  border-bottom: 1px solid transparent;
  .border-top-radius((@panel-border-radius - 1));

  > .dropdown .dropdown-toggle {
    color: inherit;
  }
}

// Within heading, strip any `h*` tag of its default margins for spacing.
.panel-title {
  margin-top: 0;
  margin-bottom: 0;
  font-size: ceil((@font-size-base * 1.125));
  color: inherit;

  > a {
    color: inherit;
  }
}

// Optional footer (stays gray in every modifier class)
.panel-footer {
  padding: 10px 15px;
  background-color: @panel-footer-bg;
  border-top: 1px solid @panel-inner-border;
  .border-bottom-radius((@panel-border-radius - 1));
}


// List groups in panels
//
// By default, space out list group content from panel headings to account for
// any kind of custom content between the two.

.panel {
  > .list-group {
    margin-bottom: 0;

    .list-group-item {
      border-width: 1px 0;
      border-radius: 0;
    }

    // Add border top radius for first one
    &:first-child {
      .list-group-item:first-child {
        border-top: 0;
        .border-top-radius((@panel-border-radius - 1));
      }
    }
    // Add border bottom radius for last one
    &:last-child {
      .list-group-item:last-child {
        border-bottom: 0;
        .border-bottom-radius((@panel-border-radius - 1));
      }
    }
  }
}
// Collapse space between when there's no additional content.
.panel-heading + .list-group {
  .list-group-item:first-child {
    border-top-width: 0;
  }
}


// Tables in panels
//
// Place a non-bordered `.table` within a panel (not within a `.panel-body`) and
// watch it go full width.

.panel {
  > .table,
  > .table-responsive > .table {
    margin-bottom: 0;
  }
  // Add border top radius for first one
  > .table:first-child,
  > .table-responsive:first-child > .table:first-child {
    .border-top-radius((@panel-border-radius - 1));

    > thead:first-child,
    > tbody:first-child {
      > tr:first-child {
        td:first-child,
        th:first-child {
          border-top-left-radius: (@panel-border-radius - 1);
        }
        td:last-child,
        th:last-child {
          border-top-right-radius: (@panel-border-radius - 1);
        }
      }
    }
  }
  // Add border bottom radius for last one
  > .table:last-child,
  > .table-responsive:last-child > .table:last-child {
    .border-bottom-radius((@panel-border-radius - 1));

    > tbody:last-child,
    > tfoot:last-child {
      > tr:last-child {
        td:first-child,
        th:first-child {
          border-bottom-left-radius: (@panel-border-radius - 1);
        }
        td:last-child,
        th:last-child {
          border-bottom-right-radius: (@panel-border-radius - 1);
        }
      }
    }
  }
  > .panel-body + .table,
  > .panel-body + .table-responsive {
    border-top: 1px solid @table-border-color;
  }
  > .table > tbody:first-child > tr:first-child th,
  > .table > tbody:first-child > tr:first-child td {
    border-top: 0;
  }
  > .table-bordered,
  > .table-responsive > .table-bordered {
    border: 0;
    > thead,
    > tbody,
    > tfoot {
      > tr {
        > th:first-child,
        > td:first-child {
          border-left: 0;
        }
        > th:last-child,
        > td:last-child {
          border-right: 0;
        }
      }
    }
    > thead,
    > tbody {
      > tr:first-child {
        > td,
        > th {
          border-bottom: 0;
        }
      }
    }
    > tbody,
    > tfoot {
      > tr:last-child {
        > td,
        > th {
          border-bottom: 0;
        }
      }
    }
  }
  > .table-responsive {
    border: 0;
    margin-bottom: 0;
  }
}


// Collapsable panels (aka, accordion)
//
// Wrap a series of panels in `.panel-group` to turn them into an accordion with
// the help of our collapse JavaScript plugin.

.panel-group {
  margin-bottom: @line-height-computed;

  // Tighten up margin so it's only between panels
  .panel {
    margin-bottom: 0;
    border-radius: @panel-border-radius;
    overflow: hidden; // crop contents when collapsed
    + .panel {
      margin-top: 5px;
    }
  }

  .panel-heading {
    border-bottom: 0;
    + .panel-collapse .panel-body {
      border-top: 1px solid @panel-inner-border;
    }
  }
  .panel-footer {
    border-top: 0;
    + .panel-collapse .panel-body {
      border-bottom: 1px solid @panel-inner-border;
    }
  }
}


// Contextual variations
.panel-default {
  .panel-variant(@panel-default-border; @panel-default-text; @panel-default-heading-bg; @panel-default-border);
}
.panel-primary {
  .panel-variant(@panel-primary-border; @panel-primary-text; @panel-primary-heading-bg; @panel-primary-border);
}
.panel-success {
  .panel-variant(@panel-success-border; @panel-success-text; @panel-success-heading-bg; @panel-success-border);
}
.panel-info {
  .panel-variant(@panel-info-border; @panel-info-text; @panel-info-heading-bg; @panel-info-border);
}
.panel-warning {
  .panel-variant(@panel-warning-border; @panel-warning-text; @panel-warning-heading-bg; @panel-warning-border);
}
.panel-danger {
  .panel-variant(@panel-danger-border; @panel-danger-text; @panel-danger-heading-bg; @panel-danger-border);
}

`

工作:我不确定出了什么问题,但我将我的面板LESS文件与默认面板LESS文件组合在一起并设法获得结果。但我确信这是编译它的错误方法。

2 个答案:

答案 0 :(得分:0)

您可以在较小的文件中包含bootstrap.less文件(@import "path";),然后对其进行编译 - 这样您将以“CSS方式”覆盖该类。或者,您可以包含bootstrap.less中包含的所有文件,但将panel.less替换为您的文件,然后进行编译。

答案 1 :(得分:0)

我通常会创建主要引导程序文件的特定于应用程序的版本,我们称之为app-bootstrap.less。只需将默认bootstrap.less的内容复制到此文件中即可。这里也有机会评论你没有使用的部分引导程序(例如弹出框,面板,表格等)。或者,如果你正在使用它,你可以@import "bootstrap.less";

您接下来要做的就是添加自己的panels.less。使用的目录搜索顺序可能由您的设置确定,但我想在@import "panels.less";app-bootstrap.less表示一件事(即从本地目录“导入panels.less”这不是一件容易的事。 )和panels.less中的另一个(即“从引导程序中导入panels.less”。因此,您可以做的是将您的面板添加内容添加到app-panels.less中,并确保在您的{{{}}中导入该文件{1}}。