Forum Moderators: not2easy
#first_one .has_top_border will have a border because the class has a border. #first_one is an id, not a class. You can only use the #id once on a page. Classes can be used again and again. So if they all have a border except one, use the #id to set the properties for the one that is different from the rest - or use a different class. :hidden; as a variable for the display property of an element, but not a property. It doesn't work.
Now I know that the DIV above SHOULD have a border. But if I try something like this:
#first_one .has_top_border {
border-top: hidden;
}
It still has a border.
#first_one.has_top_border {
border-top: hidden;
}
You can use :hidden; as a variable for the display property of an element, but not a property. It doesn't work.
Are you saying that I have to give the tenth div a different class entirely if I want to change ONE of the properties?
.has_top_border {
border-top: 1px solid #999999;
}
.has_top_border:first-child {
border-top: hidden;
}
<div class="has_top_border">
This is the first div. It should NOT have a top border
</div>
<div class="has_top_border">
This has a top border
</div>
<div class="has_top_border">
This has a top border
</div>
"Simplest approach: don't use ids for styling at all. You don't need them."
"That's because the selector you've written means "All class 'has_top_border' that are CHILDREN of the element with id 'first_one'". But in your markup, the .has_top_border is not a child of #first_one, it's the same element."
I was JUST ABOUT TO start a thread asking, "What is the difference between "#some_id .some_class and" "#some_id.some_class"
When there's no space, and the elements on both sides are id and/or class names rather than element types, it means "An element that belongs to BOTH of these."
.bar {
color: red;
}
.foo .bar {
color: blue;
} <p class="bar"> This is red</p>
<div class="foo">
<p class="bar">This is blue</p>
<div>
<p class="bar">This GRANDchild of .foo is ALSO blue</p>
<div><p class="bar">This GREAT-grandchild of .foo is ALSO blue</p>
</div>
</div>
</div>
A class can be VERY useful when combined with JavaScript as well. You can most definitely have classes that apply no presentation but are used by scripts to attach event handlers, or perform some other function.
has a parent / grandparent element at ANY level
table.foo td {blahblah}
tbody.widget tr {blahblah}
tr.bar td {blahblah}