XHTML empty DIV tags

Reply

Join Date: Nov 2007
Posts: 86
Reputation: sagedavis is an unknown quantity at this point 
Solved Threads: 6
sagedavis sagedavis is offline Offline
Junior Poster in Training

XHTML empty DIV tags

 
0
  #1
Nov 28th, 2007
Hey all,
I have a div tag in which is a basic place holder, calling CSS to clear some floats of previous div tags. They are currently being used like

HTML and CSS Syntax (Toggle Plain Text)
  1. <div id="clear"></div>

Does my code validate better, or is it better practice to use

HTML and CSS Syntax (Toggle Plain Text)
  1. <div id="clear" />
instead?
Will any browsers have trouble if I do it the second way?
Thanks
Sage
Last edited by sagedavis; Nov 28th, 2007 at 3:09 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 48
Reputation: CertGuard is an unknown quantity at this point 
Solved Threads: 3
CertGuard's Avatar
CertGuard CertGuard is offline Offline
Light Poster

Re: XHTML empty DIV tags

 
0
  #2
Nov 28th, 2007
I'm not sure what would happen in your case, but you can try it here and see what it does

http://www.w3schools.com/xml/tryit.a...ttprequest_js1

I suggest leaving it as you originally have it, it's not doing any harm that way and it is sure to work with all browsers.
--
Robert Williams
CEO, Founder
CertGuard
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 247
Reputation: cmills83 is an unknown quantity at this point 
Solved Threads: 1
cmills83 cmills83 is offline Offline
Posting Whiz in Training

Re: XHTML empty DIV tags

 
0
  #3
Dec 3rd, 2007
You could always just add clear:both to the next div under the floats and that will clear them as well.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,203
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 165
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: XHTML empty DIV tags

 
0
  #4
Dec 4th, 2007
The second way does not validate. The div tag is not self-closing. A tag is defined as being either a tag pair, or self-closing. It can't be both.

Many browsers totally ignore a pair of tags with no contents.
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 13
Reputation: vishwebdesign is an unknown quantity at this point 
Solved Threads: 1
vishwebdesign's Avatar
vishwebdesign vishwebdesign is offline Offline
Newbie Poster

Re: XHTML empty DIV tags

 
0
  #5
Dec 10th, 2007
Do not use id to identify the div you're using to clear the floats, because you might be using it several times in your document and your mark-up won't be validated. In fact, you do not even need to use the div to clear them. Use a <span class="clr"></span>

<style>
.clr
{
clear:both;
display:block;
line-height:1px;
font-size:1px;
}
</style>

and that should do the work. I thought of doing it myself, but i'm not getting time to update my website, still using divs to clear float ;-)
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 1
Reputation: igmuska is an unknown quantity at this point 
Solved Threads: 0
igmuska igmuska is offline Offline
Newbie Poster

Re: XHTML empty DIV tags

 
0
  #6
Jun 17th, 2008
Now I am completely confused about the empty div tag. I do know that the div creates a line break before and after its rendering but have read where a <br /> element is styled inline with clear:both.

I've seen recommendations to clear floats, using the empty div tag:
HTML and CSS Syntax (Toggle Plain Text)
  1. <div style="clear:both" />
And not closing the div tag.

While within another implementation of the same template, used elsewhere, I see the technique applied below:
HTML and CSS Syntax (Toggle Plain Text)
  1. <div style="clear:both; line-height:1px;"> &nbsp;</div>
Which is correct, although I just read in this topic that the first code example herein will not validate? Or is there an easier way?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 302
Reputation: sreein1986 is an unknown quantity at this point 
Solved Threads: 33
sreein1986's Avatar
sreein1986 sreein1986 is offline Offline
Posting Whiz

Re: XHTML empty DIV tags

 
0
  #7
Jun 18th, 2008
HTML and CSS Syntax (Toggle Plain Text)
  1. <div style="clear:both; line-height:1px;"> &nbsp;</div><div style="clear:both; line-height:1px;"> &nbsp;</div>
this one wrong means your styles write in div ID properties and write div tag like this
HTML and CSS Syntax (Toggle Plain Text)
  1. <div id="clear"></div>
and use in your clear
Thanx,
Shiriyal

http://shiriyal.blogspot.com/
if you problem solved add me as a reputation and mark it mark as solved
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 55
Reputation: rexibit is an unknown quantity at this point 
Solved Threads: 3
rexibit rexibit is offline Offline
Junior Poster in Training

Re: XHTML empty DIV tags

 
0
  #8
Jun 18th, 2008
You can run into some issues with IE7 making a break in your page if you are not turning off the overflow. This is a common method to clear floated elements.

HTML and CSS Syntax (Toggle Plain Text)
  1. .clearfix:after {
  2. content:".";
  3. display:block;
  4. height:0;
  5. clear:both;
  6. visibility:hidden;
  7. }
  8. .clearfix {display:inline-block;}
  9. /* Hide from IE Mac \*/
  10. .clearfix {display:block;}
  11. /* End hide from IE Mac */

Place the class "clearfix" inside the container div that has floated elements. This way, you don't have any breaks in your layout.

HTML and CSS Syntax (Toggle Plain Text)
  1. <div class="clearfix">
  2. <div class="floatedDiv">
  3. This is a floated div
  4. </div>
  5. </div>
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 16
Reputation: icorey has a little shameless behaviour in the past 
Solved Threads: 3
icorey icorey is offline Offline
Newbie Poster

Re: XHTML empty DIV tags

 
0
  #9
Jun 19th, 2008
It might depend on the content-type. Application/xhtml+xml would probably render it correctly either way, but IE would not display such a file (at all...it would ask you to open or save it).

If you were using text/html, then it would probably recognize the empty tag as a div tag that's not closed. Or this might just be an IE thing, IDK.

Back to the first tag: not having anything in between the opening and closing tags might also cause some problems.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,203
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 165
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: XHTML empty DIV tags

 
0
  #10
Jun 19th, 2008
xhtml does not allow empty tag pairs.

You can put something between the tags (such as an nbsp), and then overwrite it with the script.
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the HTML and CSS Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC