【问题标题】:CSS Custom property Url isn't working in Asp .NetCSS 自定义属性 Url 在 Asp .Net 中不起作用
【发布时间】:2021-10-02 13:25:32
【问题描述】:

我正在尝试在 mvc 项目中设置一些卡片的样式,并且我的 css“--bg-img”文件中有一个自定义属性(变量),如图所示:

 background-image: linear-gradient(rgba(0, 0, 0, var(--bg-filter-opacity)), rgba(0, 0, 0, var(--bg-filter-opacity))), var(--bg-img);

在 cshtml 文件中,我的代码如下所示:

<a class="card-posting-link posting-links" asp-action="details" asp-route-id="@item.Id" style="--bg-img: url('../../wwwroot/Uploads/@item.ImagePath')">

在 vs 代码中一切都很好,例如:

<a class="card-posting-link posting-links" href="/#/" style="--bg-img: url(/Assets/image.jpeg)">

我试过了:

~/上传

~/wwwroot/上传

以及许多其他获取图像的方法,但没有任何效果。

【问题讨论】:

    标签: css asp.net-mvc asp.net-core url css-variables


    【解决方案1】:

    解决方案是在 css 添加 css url 之前添加 c# Url.Content,如下所示:

    href="@Url.Content("~/wwwroot/Uploads/@item.ImagePath")" />
    

    您可以查看以下链接:

    https://stackoverflow.com/a/48386317/15091527

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-22
      • 2019-07-31
      • 1970-01-01
      • 2020-05-16
      相关资源
      最近更新 更多