[英]Error get-function rgba-css-var is not a valid value for background-color
I have followed the following steps to set up Bootstrap 5 SASS in the ASPNET Core project.我已按照以下步骤在 ASPNET Core 项目中设置 Bootstrap 5 SASS。
wwwroot
and select Add->Client-Side Library
.wwwroot
并选择Add->Client-Side Library
。 Selectected unpkg provider, bootstrap@5.1.3
library.bootstrap@5.1.3
@5.1.3 库。main.scss
main.scss
的文件bootsrap
in main.scssbootsrap
中的 bootsrap 导入以下内容The content of the main.scss
are: main.scss
的内容是:
@import "../lib/bootstrap/scss/bootstrap";
Web Compiler->Compile
file, the file is compiled successfully, and main.min.css
and main.css
are generatedWeb Compiler->Compile
file,文件编译成功,生成main.min.css
和main.css
_Layout.cshtml
by adding <link href="~/css/main.css" rel="stylesheet" />
<link href="~/css/main.css" rel="stylesheet" />
修改_Layout.cshtml
While loading the pages, the CSS is not generated properly.加载页面时,未正确生成 CSS。
bg-dark
or bg-light
shows the invalid values in background-color
. bg-dark
或bg-light
在background-color
中显示无效值。
Also in the visual studio there a 75 warnings from this same file main.css
.同样在视觉工作室中,来自同一个文件
main.css
的 75 个警告。
I refer to the steps mentioned in this answer and found that with a few changes it started working.我参考了此答案中提到的步骤,发现经过一些更改后它开始工作。
Note: I am using Visual Studio 2022 and I have created an Asp.Net core project with the .net core 6.0 version.注意:我使用的是 Visual Studio 2022,并且我使用 .net core 6.0 版本创建了一个 Asp.Net 核心项目。
Below are the steps to make it work.以下是使其工作的步骤。
/wwwroot/lib/bootstrap
folder./wwwroot/lib/bootstrap
文件夹中的文件。WWWroot
folder.WWWroot
文件夹。 Click on Add-> Clientside library
option.Add-> Clientside library
选项。bootstrap
and select choose specific files
option.bootstrap
并选择choose specific files
选项。 Then check the SCSS
folder.SCSS
文件夹。 Modify the Target location as below.wwwroot/lib/bootstrap/scss
and create a file named bootstrap-custom.scss
.wwwroot/lib/bootstrap/scss
并创建一个名为bootstrap-custom.scss
的文件。 $primary: #00ffff; $white: white; @import "~/lib/bootstrap"; nav.navbar { background: linear-gradient($primary, $white) }
wwwroot/lib/bootstrap/scss
location and right click the file bootstrap-custom.scss
.wwwroot/lib/bootstrap/scss
位置并右键单击文件bootstrap-custom.scss
。 Select Web compiler -> Compile file
option.Web compiler -> Compile file
选项。bootstrap-custom.css
and bootstrap-custom.min.css
files on the same location.bootstrap-custom.css
和bootstrap-custom.min.css
文件。 Copy both files to the wwwroot/css
folder.wwwroot/css
文件夹。_Layout.cshtml
file and add a reference to the bootstrap-custom.css
._Layout.cshtml
文件并添加对bootstrap-custom.css
的引用。 Also, add comments to the lines below. Note It's up to you, where you keep the compiled CSS files.注意由您决定将编译后的 CSS 文件保存在哪里。 You just need to make sure you are passing the correct path in the layout file.
您只需要确保在布局文件中传递正确的路径。
@*<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />*@ <link href="~/lib/bootstrap/scss/bootstrap-custom.css" rel="stylesheet" /> @*<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>*@
Output:输出:
Note: You may need to make some changes according to your environment to make it work on your side.注意:您可能需要根据您的环境进行一些更改以使其在您身边工作。
I was experiencing the same issue.我遇到了同样的问题。 Turned out to be the SASS Compiler I was using.
原来是我使用的 SASS 编译器。 I'm running a .NET MVC C# Web App, and had installed this VS extension with VS 2019. After discovering the error that was generated with bg-primary I started googling the cause.
我正在运行一个 .NET MVC C# Web 应用程序,并已使用 VS 2019 安装了此VS 扩展。在发现 bg-primary 生成的错误后,我开始搜索原因。 I found the answer in this thread, and switched to using the newer SASS Compiler found here .
我在这个线程中找到了答案,并切换到使用较新的 SASS Compiler found here 。 After compiling the SASS again with the new compiler (which was developed by the same person "Mad Kristensen") the problem was resolved.
在使用新编译器(由同一个人“Mad Kristensen”开发)再次编译 SASS 后,问题得到解决。
So if you're using the same compiler try switching to the newer version.因此,如果您使用相同的编译器,请尝试切换到较新的版本。 You might be able to use the compiler stated in @Deepak-MSFT answer but I haven't tried that one.
您也许可以使用@Deepak-MSFT 答案中所述的编译器,但我还没有尝试过那个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.