【问题标题】:Reverse engineering LESS from CSS从 CSS 逆向工程 LESS
【发布时间】:2016-05-09 19:11:39
【问题描述】:

如何在 Bootstrap LESS 文件中追溯(“逆向工程”)CSS?

我在 Joomla 3.4.x 中使用自己的 Twitter Bootstrap (3.x) 模板创建了一个网站。 Bootstrap 附带了很多 LESS 文件,我使用 Crunch 从中“编译”我的 bootstrap.min.css 文件。 Bootstrap 中有 40 多个 LESS 文件和近 30 个 mixin LESS 文件,它们都“编译”为 bootstrap.min.css

我对 LESS 文件进行了一些更改,以根据自己的喜好设置网站样式。除此之外,我还制作了一个 custom.less 文件,并将其合并到 bootstrap.less 文件中:@import custom.less

将 CSS 文件上传到我的网站后,我会访问该网站并使用 Firebug 处理 CSS。我进行了更改,当我喜欢这些更改时,我想在我的 Bootstrap LESS 文件中应用更改,但我发现很难追溯 CSS 的来源。

示例:在 Firebug 中,我为下拉菜单找到了这个:

.dropdown-menu > li > a {
clear: both;
color: #333333;
display: block;
font-weight: normal;
line-height: 1.7;
padding: 3px 20px;
white-space: nowrap;
}

经过长时间的搜索,我在 dropdowns.less 中发现了这个:

.dropdown-menu {
...
   // Links within the dropdown menu
  > li > a {
    display: block;
    padding: 3px 20px;
    clear: both;
    font-weight: normal;
    line-height: @line-height-base;
    color: @dropdown-link-color;
    white-space: nowrap; // prevent links from randomly breaking onto new lines
  }
  }

当然,我可以将我的 custom.less 称为 bootstrap.less 文件中的最后一个文件,并在其中写入所有样式覆盖,但在我看来,我会创建很多多余的代码,最终会使网站速度较慢。

有没有一种简单的方法可以在我的 LESS 文件中找到负责我要更改的 CSS 的 LESS 代码?还是有更好的“编译器”让我在 LESS 文件中追溯 CSS?

感谢

汤姆, 汤姆斯特丹网页设计

【问题讨论】:

  • 看起来很有希望!当网络在互联网服务器上“实时”并且源文件在我的本地计算机上时,我也可以使用它吗? (我在 Windows 7 中工作)
  • 嗯,有很多方法可以使用源地图。它们可能指向原始文件,可能指向作为 cmets 直接注入到最终 css 中的源代码等等。因此,这完全取决于您如何构建它们、您希望它们做什么以及特定浏览器支持什么。开始使用它们更容易(Crunch 使用相同的参考 Less 编译器库,因此它应该具有所有相应的选项)并看看有什么可能。

标签: css twitter-bootstrap less firebug reverse


【解决方案1】:

Firefox DevTools 和 Chrome DevTools 允许display and edit the original LESS files using source maps

但请注意,Firebug 不提供此功能。

【讨论】:

  • 非常感谢,塞巴斯蒂安!我会深入研究这个 a.s.a.p.
猜你喜欢
  • 2012-08-26
  • 1970-01-01
  • 2012-05-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-21
  • 2016-09-27
  • 1970-01-01
  • 2012-03-15
相关资源
最近更新 更多