Advertisements

"Samuël van Laere" <> wrote in
news:aJUob.43163$:
> 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.

"William Tasso" <> schreef in bericht
news:bo18e8$1660k8$-berlin.de...
> Samuël van Laere wrote:
> > 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?
>
> --
> William Tasso - http://WilliamTasso.com
>
>

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

In article <bo2thu$1pa7$>,
"Samuël van Laere" <> wrote:
> 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.

While the city slept, William Tasso <> feverishly typed:
> Samuël van Laere wrote:
>> 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?

"Kris" <> schreef in bericht
news:4all.nl...
> In article <bo2thu$1pa7$>,
> "Samuël van Laere" <> wrote:
>
> > 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.
>
> --
> Kris
> erlands (nl)

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.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!