[英]Import css/scss file into a class
I have a problem. 我有个问题。 I'm using vaadin inside liferay. 我在liferay中使用vaadin。 I've successfully written a fully responsive (yeah, tables too) theme for vaadin, based on bootstrap. 我已经基于引导程序成功地为vaadin编写了一个完全响应(是的,表格也是如此)的主题。 Now I'm importing it to liferay. 现在,我将其导入Liferay。 Everything went fine 'till I needed to upgrade Liferay, where their new responsive theme is using same classes name as bootstrap, but with different behaviour (sad, very sad face). 一切正常,直到我升级Liferay为止,他们的新响应主题使用与bootstrap相同的类名称,但行为不同(悲伤,非常可悲的表情)。
The solution I've thought so far is to apply a class to the vaadin compiled css, like: 到目前为止,我一直认为的解决方案是将类应用于vaadin编译的CSS,例如:
.daVaadinTheme {
@import bootstrap.css;
}
so the content will be compiled like: 因此内容将按以下方式进行编译:
.daVaadinTheme h1.insideTheFile{
}
.daVaadinTheme h2.insideTheFile{
}
But, as you may figured out, is not obviously working. 但是,正如您可能发现的那样,显然没有用。
Do you have any solution? 你有什么解决办法吗?
Read carefully! 仔细读! This is NOT a duplicate of the answer you've posted. 这与您发布的答案不重复。 I'm trying to import a CSS file inside a CSS/SCSS class of another file, like the example I've written above. 我正在尝试在另一个文件的CSS / SCSS类中导入CSS文件,就像我上面编写的示例一样。 My problem is not to simply import a CSS file inside another one... 我的问题不是要简单地将CSS文件导入另一个文件中...
SOLUTION: (kudos to Mathias Jørgensen) 解决方案:(对MathiasJørgensen表示敬意)
using @import from another scss file: 从另一个scss文件使用@import:
in test.scss: 在test.scss中:
.daVaadinTheme{
@import "bootstrap.scss";
}
Name your inner file with an underscore, and ending in scss. 用下划线命名您的内部文件,并以scss结尾。 .Yes, even if it's plain css, ie foo.css
→ _foo.scss
是的,即使是普通的CSS, foo.css
→ _foo.scss
Have an outer File like so: 有一个外部文件,如下所示:
#main .content { // if that's, where you want them to rule only
@import 'foo';
}
Reasons: 原因:
gulp.src(<some wildcards).sass()
) 下划线文件被sass跳过(也与gulp.src(<some wildcards).sass()
)) You need move your code into mixin
: 您需要将代码移入mixin
:
// botstrap.scss
@mixin bootstrap {
h1.insideTheFile{
}
h2.insideTheFile{
}
}
Then, you can import normal: 然后,您可以导入normal:
// test.scss
@import "bootstrap"; // No extension
@include bootstrap; // The name of "mixin"
or with context: 或结合上下文:
// test.scss
@import "bootstrap"; // No extension
.daVaadinTheme {
@include bootstrap; // The name of "mixin"
}
如果您想使用sass / scss向类中添加某些样式,我想您正在寻找的是
.myClass { @import bootstrap.css; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.