Can a div tag have two classes?
I am using twitter bootstrap, and there are two predefined classes that I would like to use.
One is an active
class that I would like to use on a dropdown-toggle
within a nav bar.
What is the best way of approaching this in the html, with out overriding the css.
This question is related to
html
css
twitter-bootstrap
space is used to make multiple classes:
<div class="One Two Three"> </div>
A div can can hold more than one classes either using bootstrap or not
<div class="active dropdown-toggle my-class">Multiple Classes</div>
For applying multiple classes just separate the classes by space.
Take a look at this links you will find many examples
http://getbootstrap.com/css/
http://css-tricks.com/un-bloat-css-by-using-multiple-classes/
You can add as many classes to an element, but you can add only one id per element.
<div id="unique" class="class1 class2 class3 class4"></div>
You can have multiple css class
selectors:
For e.g.:
<div class="col-md-4 a-class-name">
</div>
but only a single id
:
<div id = "btn1 btn"> <!-- this is wrong -->
</div>
Yes, div can take as many classes as you need. Use space to separate one from another.
<div class="active dropdown-toggle custom-class">Example of multiple classses</div>
separate the classes with a space.
<button class="btn btn-success dropdown-toggle active" data-toggle="dropdown">Success <span class="caret"></span></button>
I'm not sure if you're asking specifically about bootstrap, i.e., whether or not those two classes can be used together or if you're just asking in general?
You can apply as many classes to an element as you want, just separate class names with a space
<div class="active dropdown-toggle"></div>
Absolutely, divs can have more than one class and with some Bootstrap components you'll often need to have multiple classes for them to function as you want them to. Applying multiple classes of course is possible outside of bootstrap as well. All you have to do is separate each class with a space.
Example below:
<label class="checkbox inline">
<input type="checkbox" id="inlineCheckbox1" value="option1"> 1
</label>
Source: Stackoverflow.com