简体   繁体   English

CSS类无法正常工作MVC Visual Studio

[英]css class not working mvc visual studio

I have declare a class in my site.css file as follows: 我在site.css文件中声明了一个类,如下所示:

.CMenu1 {
  display:inline;
}

Then I have tried to use that class to style my list in Index.cshtml like so: 然后,我尝试使用该类在Index.cshtml中设置样式,如下所示:

<ul class="CMenu1">
  <li>Apples</li>
  <li>Bananas</li>
  <li>Lemons</li>
  <li>Oranges</li>
</ul>

However when I run the solution it continues to show the default style for a list, why? 但是,当我运行该解决方案时,它继续显示列表的默认样式,为什么?

You need to apply the css to the <li> elements to make them inline. 您需要将CSS应用于<li>元素以使其内联。

 .CMenu1 li{ display:inline; } 
 <ul class="CMenu1"> <li>Apples</li> <li>Bananas</li> <li>Lemons</li> <li>Oranges</li> </ul> 

Anyone looking for a solution to a problem other than what OP have asked for - 寻求除OP要求之外的其他问题的解决方案的人-
Sometimes the class is not added to the Site.css even after rebuilding the project. 有时,即使重建项目后,该类也不会添加到Site.css The problem here is that Site.css is not getting updated in the project even though we have modified it. 这里的问题是,即使我们已经对其进行了修改, Site.css也不会在项目中得到更新。 In this case, clean followed by rebuild or build would do the trick. 在这种情况下,先clean rebuildbuild

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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