Finding Harmony Between Classes/IDs & Elements

  • Thread starter Thread starter honestrosewater
  • Start date Start date
  • Tags Tags
    Elements
AI Thread Summary
In CSS, specificity determines which styles are applied when multiple rules could affect the same element. Classes and IDs generally have higher specificity than element selectors, meaning they will override styles applied to elements without classes or IDs. This principle holds true across all elements, including divs and paragraphs. The discussion highlights that CSS is read in a procedural manner, where the last rule applied takes precedence unless overridden by an !important declaration. Concerns about browser compatibility, particularly with Internet Explorer, are noted, but the main focus remains on understanding CSS specificity and its implications for styling elements effectively.
honestrosewater
Gold Member
Messages
2,133
Reaction score
6
Going with the idea that every bit counts, in situations like:
h1, h1.box {
font-size: 1em;
color: #0033cc;
letter-spacing: 0.05em;
}
h1 {margin: 1em;}
h1.box {margin: .2em .5em;}
Can I reduce it to:
h1 {
font-size: 1em;
color: #0033cc;
letter-spacing: 0.05em;
margin: 1em;
}
h1.box {margin: .2em .5em;}
without causing any browser compatibility/bug problems?

In short, will classes and ids *always* win out over nonclasses and non ids, for all elements (div, p, etc.) and settings (position, width, etc.)? Or is there another reason I should despise IE?
Thanks a bushel :biggrin:

Happy thoughts
Rachel
 
Computer science news on Phys.org
CSS is read procedurally, so whatever line was read last will stick unless there is a !important attribute attached.
 
In my discussions elsewhere, I've noticed a lot of disagreement regarding AI. A question that comes up is, "Is AI hype?" Unfortunately, when this question is asked, the one asking, as far as I can tell, may mean one of three things which can lead to lots of confusion. I'll list them out now for clarity. 1. Can AI do everything a human can do and how close are we to that? 2. Are corporations and governments using the promise of AI to gain more power for themselves? 3. Are AI and transhumans...
Sorry if 'Profile Badge' is not the correct term. I have an MS 365 subscription and I've noticed on my Word documents the small circle with my initials in it is sometimes different in colour document to document (it's the circle at the top right of the doc, that, when you hover over it it tells you you're signed in; if you click on it you get a bit more info). Last night I had four docs with a red circle, one with blue. When I closed the blue and opened it again it was red. Today I have 3...

Similar threads

Replies
4
Views
3K
Replies
3
Views
2K
Replies
3
Views
3K
Replies
4
Views
4K
Replies
7
Views
3K
Replies
9
Views
3K
Back
Top