Jump to content

Layers And Divs And Ids


Malpractice

Recommended Posts

Do not take this as a dumb question please, I am quite serious even if it makes me appear dumb.is a div the same as a layer and is an id the same as a div or layer etc etc, I really am struggling to comprehend the differences, anyone fancy trying to enlighten and old ###### ?

Link to comment
Share on other sites

There's really no such thing as a "layer" really, it's just an abstract concept, not a particular thing. A div could be a layer, but so could a table, a span, a <p>, whatever. A "layer" is really just any container element that you've put some CSS properties on so that it floats above everything else, or maybe is positioned in a specific place, or whatever (however you want to define "layer"). A div is just a generic block-level container, and an ID just uniquely identifies any one element (a given ID should only be used on one element on a page).

Link to comment
Share on other sites

Layer was a term Netscape invented back in the 90's for a container that could exist "in front of" or "behind" other page elements. When HTML was rewritten by the W3 Consortium, the "container" aspect of a layer was transformed into the div element, which had not existed before. The concept of layering, as JSG pointed out, was extended to all page elements. It is controlled through the CSS z-index property. Coordinate positioning was also a part of layers, and that too has been extended to all page elements.If you see a script that refers to document.layers, run for your life. It's so old it's toxic.

Link to comment
Share on other sites

Do not take this as a dumb question please, I am quite serious even if it makes me appear dumb.is a div the same as a layer and is an id the same as a div or layer etc etc, I really am struggling to comprehend the differences, anyone fancy trying to enlighten and old ###### ?
An "id" is a property that most things have. A <div id="xxx"> or a <p id="yyy"> or a <img id="zzz"> are all valid. It is a way to uniquely identify something. You can apply styles to an "id" in css like #xxx {stuff;} or #yyy {other stuff;}.
Link to comment
Share on other sites

ok, I kind of thought along these lines, but I was not sure, next question, why do you uniquely want to identify an element (again this question comes from reading other peoples code and seeing more than "ID" on a web page (OR AM i MISSING SOMETHING HERE ?)) Please can you give me an example Thanks for your patience

Link to comment
Share on other sites

It is illegal to have more than one element per ID.The main reason to uniquely identify elements is to provide a way to reference them using JavaScript (e.g. through the getElementById() method). It also can speed up rendering slightly as the CSS parser can continue after finding the first instance of an ID (though I don't believe this happens).

Link to comment
Share on other sites

ok, I kind of thought along these lines, but I was not sure, next question, why do you uniquely want to identify an element (again this question comes from reading other peoples code and seeing more than "ID" on a web page (OR AM i MISSING SOMETHING HERE ?)) Please can you give me an example Thanks for your patience
You've seen those "Jump to top of page" things, right? One thing they can jump to is a named anchor. But that requires you to add one. They can also jump to an ID which would require it to be unique so the page would know where to jump to.You also gain some clarity so when you see it in the css, you know it applies to one and only one place on the page.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...