【问题标题】:Nested LESS to css classes将 LESS 嵌套到 css 类
【发布时间】:2015-07-30 11:23:30
【问题描述】:

我正在尝试从我的 css 中减少一些,现在我已经做了很多,但是我对 KENDO Grid 的长选择器有问题,它将元素包裹在奇怪的地方,然后很难找到。这就是我现在所拥有的

        .k-grid {
        .k-pager-wrap {
            .color-background(@white);
            border-top: 0 none;
        }

        .k-grid-header {
            .color-background(@white);

            thead tr[role="row"]:first-child {
                display: none;
            }

            .k-grid-header-wrap {
                table {
                    thead {
                        tr {
                            th.k-header {
                                font-size: @font-size-large;
                            }
                        }
                    }
                }
            }
        }

        .k-grid-content {
            overflow: auto !important;
        }
    }

     .k-pager-numbers {
    li {
        a.k-link {
            .color-text(@grey) !important;

            &:hover, &:active, &:focus, &:visited {
                .color-background(@grey-background) !important;
                .color-text(@brand) !important;
            }
        }

        .k-state-selected {
            .color-background(@grey-background) !important;
            border: medium none;
            .color-text(@brand);
        }
    }
}

问题是我有另一个 CSS,我试图把这个 k-grid 放在这个 k-grid 的 inisde 中,这里是

CSS

        .k-grid-header-wrap table thead tr.k-filter-row th span.k-filtercell span.k-operator-hidden button.k-button.k-button-icon {
    height: 26px;
}

.k-grid-header-wrap table thead tr.k-filter-row th span.k-filtercell span.k-operator-hidden button.k-button.k-button-icon span.k-icon.k-i-close {
    margin-bottom:18px;
}


table thead tr.k-filter-row th span.k-filtercell span.k-operator-hidden span.k-widget.k-autocomplete.k-header.k-state-focused,
table thead tr.k-filter-row th span.k-filtercell span.k-operator-hidden span.k-widget.k-autocomplete.k-header.k-state-hover {
    .lh-box-shadow(none) !important;
    border-color: @grey-border !important;
}

.k-grid-header-wrap table thead tr.k-filter-row th {
    padding-top:5px;
    padding-bottom:5px;
}


div.k-grid-header div.k-grid-header-wrap {
    border-right-width: 0;
    width: 101%;
}

您可能会看到它是非常长的选择器,但是我需要将我所有的 CSS 转换为我已经拥有的更少,只是为了附加 LESS,有人可以帮助我。我已经失去了一整天的时间,因为现在用这个 CSS 我没有运气。赠品

【问题讨论】:

  • 你已经尝试过在线转换 css 来减少像 this 那样的东西?
  • @NikunjChotaliya - 您可能想将其发布为答案。干杯!

标签: css less mixins nested


【解决方案1】:

你可以为你的选择器提供变量。 你的代码可以是这样的:

  @first-long-selector: ~"span.k-filtercell span.k-operator-hidden button.k-button.k-button-icon";
  @second-long-selector: ~"span.k-filtercell span.k-operator-hidden span.k-widget.k-autocomplete.k-header";
  @short-selector: k-grid-header;
  @table-selector: ~"table thead tr.k-filter-row th";

  .@{short-selector}{
    &-wrap{
      @{table-selector}{
          @{first-long-selector} {
          height: 26px;

            .k-icon.k-i-close{
              margin-bottom:18px;
            }
          }
      }
    }
  }

  @{table-selector}{
    @{second-long-selector}{
        &.k-state-focused,
        &.k-state-hover{
          .lh-box-shadow(none) !important;
          border-color: @grey-border !important;
        }  
    }
  }

  .@{short-selector}{
    &-wrap{
      @{table-selector}{
        padding-top:5px;
        padding-bottom:5px;
      }
    }
  }


  .@{short-selector}{
    & &-wrap{
      border-right-width: 0;
      width: 101%;
    }
  }

这是example

【讨论】:

  • 你也可以在需要的时候在变量中做变量。
【解决方案2】:

LESS 可识别 CSS。因此,您不必将 CSS 转换为 LESS。如果您只是想让它工作,只需按原样复制即可。

【讨论】:

  • 我知道,但它的选择器太长了,一定有人看那个
  • 实际上 IMO 正确的缩进实际上会使维护 esp 变得更加困难。因为您没有在该级别添加其他样式。但是请看一下 Nikunj 的建议——这似乎是一种将 CSS 转换为 LESS 的好方法。干杯!
猜你喜欢
  • 2011-10-20
  • 2023-02-24
  • 1970-01-01
  • 2013-02-13
  • 2012-03-11
  • 2012-07-16
  • 2012-09-15
  • 2012-07-17
  • 1970-01-01
相关资源
最近更新 更多