问题
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