How can I put multiple classes in a <li> element?

允我心安 提交于 2019-12-13 19:20:14

问题


I am working with a navigation menu, and wondering how to put multiple classes in a li tag:

This is the li tag

 <li  class='pil' class='dropdown'>

And this is also what I want in the li tag:

class='{{ ($aktiv == 'dagvakt') ? 'active' : '' }}'

I tried this and it didn't work:

 <li  class='pil' class='dropdown'  class='{{ ($aktiv == 'dagvakt') ? 'active' : '' }}'>

回答1:


You can add multiple classes to an element by putting them all in the same class attribute and separating them with a space. For example:

<li class='pil dropdown {{ ($aktiv == 'dagvakt') ? 'active' : '' }}'>

As far as I know, the spec only allows class to be declared once, so trying <li class='ex' class='am' class='ple'> won't work.




回答2:


Only one of each attribute can exist at one time, it should be a space-separated list of classes. Try this:

<li class="pil dropdown {{ ($aktiv == 'dagvakt') ? 'active' : '' }}">

Also careful using quotes ' inside quotes, it's a good idea to use double quote " to assist syntax highlighting and to avoid any conflicts.



来源:https://stackoverflow.com/questions/23062548/how-can-i-put-multiple-classes-in-a-li-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!