I have some javascript that appends html to a div
There is an if loop, and it appends divs with exactly similar data, just difference is in the class name. So either this tag gets appended:
<div class="customer" id="0"><h2>Lorem Ipsum</h2><h3>testing</h3></div>
Or this is appended:
<div class="vehicle" id="0"><h2>Lorem Ipsum</h2><h3>testing</h3></div>
The CSS is:
For the customer classed div:
#results .customer{
height: 60px;
padding-top: 18px;
margin: 10px 0px;
border-bottom: 20px solid black;
}
#results .customer h2{
font-size: 2.5em;
}
#results .customer h3{
width: 90%;
text-align: right;
float: right;
font-size: 1.5em;
margin-top: 15px;
margin-right: 15px;
}
For the vehicles classed div:
#results .vehicle{
height: 60px;
padding-top: 18px;
margin: 10px 0px;
border-bottom: 20px solid black;
}
#results .vehicle h2{
font-size: 2.5em;
}
#results .vehicle h3{
width: 90%;
text-align: right;
float: right;
font-size: 1.5em;
margin-top: 15px;
margin-right: 15px;
}
Basically they both are the same. But only one works properly, i.e. whichever is positioned lower in the CSS file.
So here, when the vehicles classed div is appended, it displays correctly. but if the customer classed div is appended, it doesn't. The reverse would happen if i cut the cut the CSS for vehicle classed divs and paste it above the customer classed CSS.
I know CSS calculates the priority of CSS rules based on a method in which inline rules get max points, then internal styles, then external styles and in the external, 1000 points for id, 100 for tag...etc
Something like that, but when i have separate class names, then how can there be a conflict. What is happening?
Lorem
...` Doing this simplifies the style definitions, reduces the copy-paste repetition, and reduces the opportunities for errors. [DRY](http://programmer.97things.oreilly.com/wiki/index.php/Don%27t_Repeat_Yourself) = _Don't Repeat Yourself._