Is it valid?

  • Thread starter Samuël van Laere
  • Start date
S

Samuël van Laere

I just wonder if it is ok to have a empty tag?
For example:
<div id="header"></div>

It validates fine so that isn't a problem.
 
W

William Tasso

Samuël van Laere said:
I just wonder if it is ok to have a empty tag?
For example:
<div id="header"></div>

I often wonder at the purpose of empty elements.
It validates fine so that isn't a problem.

May I enquire why one would want such a thing?
 
E

Eric Bohlman

I just wonder if it is ok to have a empty tag?
For example:
<div id="header"></div>

It validates fine so that isn't a problem.

Since it validates fine (as it should; the content model for div is
"(%flow;)*" which explicitly allows empty content), it's definitely valid,
which was the question you asked in your Subject: line. If you're asking
whether it's harmful, I'm not aware of any circumstances where it is.
However, if you're going to set properties like background color, height,
and width on it in order to get colored areas or the like, IIRC some
browsers will refuse to acknowledge its existence until you put *some*
content (just an &nbsp; will usually work) in it. IOW,

div#header {background-color: red; height: 10px; width: 100%;}

might not give you a 10-pixel high red bar unless you put some content in.
 
S

Samuël van Laere

William Tasso said:
I often wonder at the purpose of empty elements.


May I enquire why one would want such a thing?

There isn't a purpose for empty elements, the best next thing to overcome
that is using &nbsp;
In my case i use <div id="header"></div> to display a logo in the header, i
don't want any text with it.
But perhaps you have a better idea?
http://www.fortron.net
 
K

Kris

Samuël van Laere said:
In my case i use <div id="header"></div> to display a logo in the header, i
don't want any text with it.

Why not put an <img> inside there that gets hidden by CSS for screen
display and shown on print-out as that nice company logo on white? Can
also contain some nice ALTernative text to represent your company to
search engines that (naturally) do not see your logo.
 
N

nice.guy.nige

While the city slept said:
I often wonder at the purpose of empty elements.


May I enquire why one would want such a thing?

Well... you never know when it might come in handy? ;-)

Cheers,
Nige

--
Nigel Moss.

Email address is not valid. (e-mail address removed). Take the dog out!
http://www.nigenet.org.uk | Boycott E$$O!! http://www.stopesso.com
In the land of the blind, the one-eyed man is very, very busy!
 
S

Samuël van Laere

Kris said:
Why not put an <img> inside there that gets hidden by CSS for screen
display and shown on print-out as that nice company logo on white? Can
also contain some nice ALTernative text to represent your company to
search engines that (naturally) do not see your logo.

Thanks for your comments Kris.

I'm not sure if it will be a improvement, i use a different logo for some
styles.
I haven't used any <img> tags so far.
Right now i use &nbsp; for the element and that works.

Besides how do i hide a <img> anyway?
 
O

Owen Jacobson

Samukl said:
Besides how do i hide a <img> anyway?

In your stylesheet, assuming you're still using <div id="header"> (try
<h1>, that's probably a better fit):

@media screen {
#header img { display: none; }
}

If you replace your DIV with an H1, similarly replace #header with h1.

(Fix your sig separator, eh?)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top