使用 Razor 将样式编程盟友添加到垂直导航菜单时出现的问题
我正在尝试在我的一个项目中使用剃刀装饰垂直导航菜单,我正在尝试根据功能添加样式但没有成功,问题是我的子类别和类别都在一张表中,这就是为什么我必须调用一个 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.
:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您向标记添加两个
style
属性。我会把它们合二为一。
并稍微清理一下 LI 标签的生成。首先进行测试,并将结果存储在一些变量中:
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: