使用 Razor 将样式编程盟友添加到垂直导航菜单时出现的问题

发布于 2024-12-19 21:39:09 字数 2184 浏览 1 评论 0原文

我正在尝试在我的一个项目中使用剃刀装饰垂直导航菜单,我正在尝试根据功能添加样式但没有成功,问题是我的子类别和类别都在一张表中,这就是为什么我必须调用一个 ul 中的所有类别、子类别,然后在悬停、活动、非活动等上装饰它们。下面是代码,以及为什么粗体语句不起作用的任何想法。

  <div class="listbox">
        <ul class="">
            @foreach (var category in Model)
            {
                <li class="@(category.IsActive ? "active" : "inactive")" 
               @if (category.NumberOfParentCategories > 0)

                {

                  <text>style="background-image: url('/Content/images/cat-ul-li-list.png');border-bottom-style: solid;border-bottom-width:1px; border-bottom-color: #FFFFFF;font-size: 13px;
text-decoration: none;
padding-top: 4px;
padding-left: 15px;color:#5F9E95;min-height:27px;"</text>

                   }
                   **@if (category.NumberOfParentCategories > 0 && category.IsActive == true) 


                    {

                    <text>style="background-image: url('/Content/images/cat-ul-li-active.png') !Important;"</text>**
                    }><a href="@Url.RouteUrl("Category", new { categoryId = category.Id, SeName = category.SeName })">@category.Name

                </a>
                 </li><li class="separator"></li>
            }
        </ul>
    </div>

Css:

.block-category-navigation .listbox ul .inactive
{
background-image: url('images/cat-rt-arrow.png');
background-repeat: no-repeat;
background-position: left center;
border-bottom-width: 1px;
border-bottom-color: #5F9E95;
border-bottom-style: solid;
padding-left:15px;
min-height:27px;
padding-top:8px;
}

.block-category-navigation .listbox ul li a:hover { color: #404041; }
 .block-category-navigation .listbox ul{ background-image: url('images/cat-ul-active.png') !Important; padding-left:15px;min-height:27px; padding-top: 8px;}

演示可以在测试网站上看到:Quadratech

任何建议或帮助如果可以使用其他方法(如 css 和 jquery)来完成此操作,我们将不胜感激。我附上了我正在寻找的图像,其中止血是下面选择的类别是血红素的子类别..子类别阻力处于活动状态,而底部的右下方是其他非活动类别。 :在此处输入图像描述

I am trying to decorate the vertical navigation menu using razor in one of my projects , i am trying to add style depending on the functionality with no success , the issue is i have subcategories and categories all in one table , thats why i have to call all the categories , subcategories within a one ul and then decorate them on hover , active , inactive etc. Below is the code, any ideas why the bold statement doesnt works.

  <div class="listbox">
        <ul class="">
            @foreach (var category in Model)
            {
                <li class="@(category.IsActive ? "active" : "inactive")" 
               @if (category.NumberOfParentCategories > 0)

                {

                  <text>style="background-image: url('/Content/images/cat-ul-li-list.png');border-bottom-style: solid;border-bottom-width:1px; border-bottom-color: #FFFFFF;font-size: 13px;
text-decoration: none;
padding-top: 4px;
padding-left: 15px;color:#5F9E95;min-height:27px;"</text>

                   }
                   **@if (category.NumberOfParentCategories > 0 && category.IsActive == true) 


                    {

                    <text>style="background-image: url('/Content/images/cat-ul-li-active.png') !Important;"</text>**
                    }><a href="@Url.RouteUrl("Category", new { categoryId = category.Id, SeName = category.SeName })">@category.Name

                </a>
                 </li><li class="separator"></li>
            }
        </ul>
    </div>

Css:

.block-category-navigation .listbox ul .inactive
{
background-image: url('images/cat-rt-arrow.png');
background-repeat: no-repeat;
background-position: left center;
border-bottom-width: 1px;
border-bottom-color: #5F9E95;
border-bottom-style: solid;
padding-left:15px;
min-height:27px;
padding-top:8px;
}

.block-category-navigation .listbox ul li a:hover { color: #404041; }
 .block-category-navigation .listbox ul{ background-image: url('images/cat-ul-active.png') !Important; padding-left:15px;min-height:27px; padding-top: 8px;}

The demonstartion can be seen on test website :Quadratech

Any suggestion or assistance will be appreciated, if this can be done using other methods like css and jquery. I have attached the image of what i am exactly looking for where Haemostasis is the category selected below is the subcategories for haem.. with the subcategory resistance active, and right down the bottom are the other inactive categories.
:enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黑寡妇 2024-12-26 21:39:09

您向标记添加两个 style 属性。

我会把它们合二为一。

并稍微清理一下 LI 标签的生成。首先进行测试,并将结果存储在一些变量中:

    const string STYLEBASE= "border-bottom-style: solid;border-bottom-width:1px; border-bottom-color: #FFFFFF;font-size: 13px;
text-decoration: none;
padding-top: 4px;
padding-left: 15px;color:#5F9E95;min-height:27px;";

       var style = "";
       var backgroundimage = "";
       if (category.NumberOfParentCategories > 0) {
          backgroundimage = "background-image: url('/Content/images/cat-ul-li-list.png');";
          style = STYLEBASE;
       }

       if (category.NumberOfParentCategories > 0 && category.IsActive == true) {
          // override the background image
          backgroundimage = "background-image: url('/Content/images/cat-ul-li-active.png');
       }

       <li class="@(category.IsActive ? "active" : "inactive")" style="@Html.Raw(style + " " + backgroundimage)" >

You add two style attributes to your tag.

I would combine them into one.

And cleanup the generation for the LI tag a bit. By first doing the test, and storing the result in some variables:

    const string STYLEBASE= "border-bottom-style: solid;border-bottom-width:1px; border-bottom-color: #FFFFFF;font-size: 13px;
text-decoration: none;
padding-top: 4px;
padding-left: 15px;color:#5F9E95;min-height:27px;";

       var style = "";
       var backgroundimage = "";
       if (category.NumberOfParentCategories > 0) {
          backgroundimage = "background-image: url('/Content/images/cat-ul-li-list.png');";
          style = STYLEBASE;
       }

       if (category.NumberOfParentCategories > 0 && category.IsActive == true) {
          // override the background image
          backgroundimage = "background-image: url('/Content/images/cat-ul-li-active.png');
       }

       <li class="@(category.IsActive ? "active" : "inactive")" style="@Html.Raw(style + " " + backgroundimage)" >
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文