473,465 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

div#header vs. #header

I am retooling my design habits, trying to get rid of some mental
artifacts, and trying to "standardize" my starting point "templates"
(both html and css). I am also trying to avoid "div-itis." I find
myself using selectors like div#header instead of just #header. I know
that div#header and #header both refer to the same target, and (for me)
it is easy to see exactly what the style is being applied to. Any
thoughts, pro and con, on one method versus the other?

Sep 22 '07 #1
12 5367
On 2007-09-22, William Gill wrote:
I am retooling my design habits, trying to get rid of some mental
artifacts, and trying to "standardize" my starting point "templates"
(both html and css). I am also trying to avoid "div-itis." I find
myself using selectors like div#header instead of just #header. I know
that div#header and #header both refer to the same target, and (for me)
it is easy to see exactly what the style is being applied to. Any
thoughts, pro and con, on one method versus the other?
The do not necessarily apply to the same target. Without specifying
'div', the style could be applied to any tag with id="header"
(though, of course, there must be only one in a single page).

If you want to apply those styles to div#header in one file and
h1#header in another, use #header. If you only want them applied to
div#header, then use that.

--
Chris F.A. Johnson <http://cfaj.freeshell.org>
================================================== =================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Sep 22 '07 #2
Chris F.A. Johnson wrote:
The do not necessarily apply to the same target. Without specifying
'div', the style could be applied to any tag with id="header"
(though, of course, there must be only one in a single page).
So, like I said, they refer to the same target (on any given page.) :-)
If you want to apply those styles to div#header in one file and
h1#header in another, use #header. If you only want them applied to
div#header, then use that.
Good point. I actually hadn't thought about having tags on different
pages styled per a given ID, but this tends to defeat my
"standardization" theory.

I still like the idea that I can get a feel for the number of divs on a
page by looking at the stylesheet (i.e. div#header, div#copy,
div#footer, div#etc ...).

Sep 23 '07 #3
Scripsit William Gill:
Chris F.A. Johnson wrote:
> The do not necessarily apply to the same target. Without
specifying 'div', the style could be applied to any tag with
id="header" (though, of course, there must be only one in a
single page).

So, like I said, they refer to the same target (on any given page.)
:-)
No, on any page that has an id="header" attribute in any element that is not
a div element, #header refers to that element whereas div#header does not
refer to any element.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Sep 23 '07 #4
Chris F.A. Johnson wrote:
> The do not necessarily apply to the same target. Without specifying
'div', the style could be applied to any tag with id="header"
(though, of course, there must be only one in a single page).

So, like I said, they refer to the same target (on any given page.) :-)
Based on other replies in this thread, I realize my response wasn't
clear, and my response should have been bracketed in <humor
howfunny="notvery"</humoror more appropriately <flip</flip>.

I apologize. I was simply agreeing that since (per specification) id's
must be unique, whether I used the convention div#header or #header,
they WOULD be referring to the same target.
Sep 23 '07 #5
Jukka K. Korpela wrote:
Scripsit William Gill:
>Chris F.A. Johnson wrote:
>> The do not necessarily apply to the same target. Without
specifying 'div', the style could be applied to any tag with
id="header" (though, of course, there must be only one in a
single page).

So, like I said, they refer to the same target (on any given page.)
:-)

No, on any page that has an id="header" attribute in any element that is
not a div element, #header refers to that element whereas div#header
does not refer to any element.
So basically if you always apply the ID "header" to a DIV then the is
really no difference is using div#header over #header in your stylesheet
except your have to type 3 more characters. However the disadvantage is
in flexibility if you should ever decide to apply the style to a
different element in your markup...

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Sep 23 '07 #6
Scripsit William Gill:
Jukka K. Korpela wrote:
>No, on any page that has an id="header" attribute in any element
that is not a div element, #header refers to that element whereas
div#header does not refer to any element.

I know, div#header and #header CAN possibly refer to different
elements,
No, they cannot. Please read what I explained. It is incorrect to say that
they always refer to the same element (as you said previously), and it is
also incorrect to say that they can refer to different element (as you now
said),
but if I adopt a specific consistent naming convention
Umm...
(i.e. div#header vs. #header)
That's not a naming convention. That's a matter of using selectors.
I will never have a div with the
id="header" along with any other element having id="header" (that
would violate MY convention).
It would violate HTML syntax, in a manner that a validator would report. So
it is irrelevant whether it violates your personal conventions.
If I use just the #header
convention, it's not obvious that header is an entire div, and not
just a single h1 element.
Why would that matter? If you use #header, you can move from <h1
id="header">...</h1to <div id="header"><h1>...</h1>...</divwhenever you
decide to move something into the header but outside the h1 element. Why
would you intentionally make that more difficult?

Anyway, whatever approach you're using, both of your statements about the
relation between #header and div#header were incorrect and misleading. In a
public discussion, that's more important than your private conventions.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Sep 23 '07 #7
Scripsit Jonathan N. Little:
So basically if you always apply the ID "header" to a DIV then the is
really no difference is using div#header over #header in your
stylesheet except your have to type 3 more characters.
There is, because div#header is more specific than #header, in terms of
specificity of selectors as defined in CSS. Quite often this does not
matter, but when it does, the author is surely confused if he has learned to
think that there is no difference.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Sep 23 '07 #8
Andy Dingley wrote:
On 22 Sep, 19:16, William Gill <nore...@example.invalidwrote:
> I find
myself using selectors like div#header instead of just #header. I know
that div#header and #header both refer to the same target,

I'd strongly recommend using div.header

You can use an id attribute, but use a class attribute too, and use
the class in the CSS selector, not the id.
Agreed. I learned long ago to not use id's at all unless they are needed
for scripting purposes or for page anchors, and always leave them out of
the stylesheet.

--
Berg
Sep 24 '07 #9
Scripsit William Gill:
Now let me "Yucca parse" that:
"The selectors #header and div#header can never refer to two
different elements" but when someone other than Yucca says they
refer to the same element, that's "wrong" because they don't
"always."
Well that clears things up.
Yes, this clarifies that you don't understand the issue. That's OK, but why
do you keep trying to explain something about it when you are so confused,
as well as keep misrepresenting what others have tried to explain to you?

I'll try to type this in as slowly as I can:

They may refer to the same element, but this does not mean that they mean
the same thing. You probably don't understand this, because you don't
understand the CSS cascade.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/

Sep 24 '07 #10


Jukka K. Korpela wrote:
Scripsit William Gill:

Yes, this clarifies that you don't understand the issue. That's OK, but
why do you keep trying to explain something about it when you are so
confused, as well as keep misrepresenting what others have tried to
explain to you?

I'll try to type this in as slowly as I can:

They may refer to the same element, but this does not mean that they
mean the same thing. ...
Please show me where I said they were the same thing, or where I
misrepresent anything anyone has said, so that I may issue the
appropriate mea culpa's.

Yes, I was trying to use them to accomplish the same purpose, i.e. to
target a <div>identified as "header", not an <h1>, or a <p>, or anything
else. You still haven't said why that won't work, or why it's not a
good idea to do it that way. I take that back, you did give some
considerations why that would make things more difficult. You have made
it abundantly clear that div#header wouldn't target <h1 id="header">.
I'm sorry I don't know how else to tell you I do know that. And before
you point it out, I know that div#someotherid will not target my <div
id="header"either.
...You probably don't understand this, because you
don't understand the CSS cascade.
I am sure I don't understand it as well as you. It's too bad there
isn't a newsgroup where I can ask questions about it. :-)

Sep 24 '07 #11


Jukka K. Korpela wrote:
Scripsit William Gill:
>If I have a style sheet with both div#header and #header, the first
(more specific) will style only pages containing <div id="header">.

I have no idea of what point you are trying to make, and specificity has
nothing to do with the rather trivial fact that div#header refers to the
div element with id="header", if it exists.
A couple days later, with more sleep, and under a banner of truce :-)

If I use the selector #header, it will match any any element that is
identified as "header". If, however I employ the selector div#header it
only matches the div element identified as "header", thus it is more
specific.

My understanding of CSS specificity is that it is the arbitration used
to be used between competing rules. Absent any conflict, specificity is
meaningless.

Are these either semantically, or otherwise incorrect?


Sep 25 '07 #12


Jonathan N. Little wrote:
Well I would say as a "crutch" use a comment!
You have no idea how hard I'm laughing (at myself again). I believe in
comments too.

Sometimes I'm a real "can't see the forest" kind of guy. Now you know
why I can't work when I'm tired.
Sep 26 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Glabbeek | last post by:
I'm changing the layout of my site. Instead of using tables, I will use DIVs. It's working fine, except for 1 thing: In IE6 some DIVs are not the correct width. Mozilla and Opera are showing the...
7
by: Dan V. | last post by:
Still struggling with css. Anyone know how to put a tope background colour (matches the right part of the banner image) that stretches to the max. size of the window like the main div? My header...
2
by: JB | last post by:
Hi All, What's the difference between: #header { width: 100%; } and
1
by: Gernot Frisch | last post by:
I want to center the div "KungFu" over the div "header". Does not. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//DE"> <html> <body> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p>
2
by: bj | last post by:
Hi, Yes, this is yet another "switching from tables to divs for layout purposes" post. I have been searching for the past few hours to find what I'm looking for as I hate posting unnecessarily....
2
by: ~john | last post by:
I'm trying to get my header to have 2 images, one for the top left and one for the top right. Here's a link to my page... http://levelwave.com/dev/div/index.html and will eventually be...
5
by: shapper | last post by:
Hello, I have 3 Divs as follow: <div id="Container"> <div id="Header">header</div> <div id="Text">text</div> </div> I need the div "Text" to have an absolute position inside div
1
by: swc76801 | last post by:
I desperately need help. My understanding of CSS is non-existent. I have a store http://astore.amazon.com/texasheat-20 with Amazon.com. According to the information from Amazon.com "Write your own...
1
by: adz1809 | last post by:
I have a page with the following code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.