简体   繁体   English

错误 get-function rgba-css-var is not a valid value for background-color

[英]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。

  1. right-click wwwroot and select Add->Client-Side Library .右键单击wwwroot并选择Add->Client-Side Library Selectected unpkg provider, bootstrap@5.1.3 library.选定的 unpkg 提供程序, bootstrap@5.1.3 @5.1.3 库。
  2. Created a file called main.scss创建了一个名为main.scss的文件
  3. Imported following from bootsrap in main.scssbootsrap中的 bootsrap 导入以下内容

The content of the main.scss are: main.scss的内容是:

@import "../lib/bootstrap/scss/bootstrap";
  1. right-click the main.scss file and select Web Compiler->Compile file, the file is compiled successfully, and main.min.css and main.css are generated右键main.scss文件,选择Web Compiler->Compile file,文件编译成功,生成main.min.cssmain.css
  2. Modified _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-darkbg-lightbackground-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.以下是使其工作的步骤。

  1. After creating the project, I deleted the files in /wwwroot/lib/bootstrap folder.创建项目后,我删除了/wwwroot/lib/bootstrap文件夹中的文件。
  2. Right-click the WWWroot folder.右键单击WWWroot文件夹。 Click on Add-> Clientside library option.单击Add-> Clientside library选项。
  3. Search for bootstrap and select choose specific files option.搜索bootstrap并选择choose specific files选项。 Then check the SCSS folder.然后检查SCSS文件夹。 Modify the Target location as below.修改目标位置如下。

在此处输入图像描述

  1. Browse thru 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) }

  1. Installed the extension below and restart the Visual Studio.安装了下面的扩展并重新启动 Visual Studio。

在此处输入图像描述

  1. Browse thru 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选项。

在此处输入图像描述

  1. It will create a bootstrap-custom.css and bootstrap-custom.min.css files on the same location.它将在同一位置创建bootstrap-custom.cssbootstrap-custom.min.css文件。 Copy both files to the wwwroot/css folder.将这两个文件复制到wwwroot/css文件夹。

在此处输入图像描述

  1. Go to the _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>*@

  1. Run the project.运行项目。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM