User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the HTML and CSS section within the Web Development category of DaniWeb, a massive community of 391,768 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,169 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our HTML and CSS advertiser: Lunarpages Web Hosting
Views: 2167 | Replies: 9
Reply
Join Date: Nov 2007
Posts: 86
Reputation: sagedavis is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
sagedavis sagedavis is offline Offline
Junior Poster in Training

Help XHTML empty DIV tags

  #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

<div id="clear"></div>

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

<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 2:09 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2007
Posts: 48
Reputation: CertGuard is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 3
CertGuard's Avatar
CertGuard CertGuard is offline Offline
Light Poster

Re: XHTML empty DIV tags

  #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  
Join Date: Jun 2004
Posts: 210
Reputation: cmills83 is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
cmills83 cmills83 is offline Offline
Posting Whiz in Training

Re: XHTML empty DIV tags

  #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  
Join Date: Jan 2007
Posts: 2,510
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 103
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: XHTML empty DIV tags

  #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  
Join Date: Nov 2007
Posts: 10
Reputation: vishwebdesign is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
vishwebdesign's Avatar
vishwebdesign vishwebdesign is offline Offline
Newbie Poster

Re: XHTML empty DIV tags

  #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  
Join Date: Jun 2008
Posts: 1
Reputation: igmuska is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
igmuska igmuska is offline Offline
Newbie Poster

Re: XHTML empty DIV tags

  #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:
<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:
<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  
Join Date: May 2008
Location: Hyderabad, India
Posts: 245
Reputation: sreein1986 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 27
sreein1986's Avatar
sreein1986 sreein1986 is offline Offline
Posting Whiz in Training

Re: XHTML empty DIV tags

  #7  
Jun 18th, 2008
<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
<div id="clear"></div> 
and use in your clear
Thanx,
Sreekanth

www.saap.in
if you problem solved add me as a reputation and mark it mark as solved
Reply With Quote  
Join Date: Jun 2008
Posts: 50
Reputation: rexibit is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
rexibit rexibit is offline Offline
Junior Poster in Training

Re: XHTML empty DIV tags

  #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.

.clearfix:after {
content:".";
display:block;
height:0;
clear:both;
visibility:hidden;
}
.clearfix {display:inline-block;}
/* Hide from IE Mac \*/
.clearfix {display:block;}
  /* 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.

<div class="clearfix">
<div class="floatedDiv">
This is a floated div
</div>
</div>
Reply With Quote  
Join Date: Jun 2008
Posts: 16
Reputation: icorey has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 2
icorey icorey is offline Offline
Newbie Poster

Re: XHTML empty DIV tags

  #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  
Join Date: Jan 2007
Posts: 2,510
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 103
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: XHTML empty DIV tags

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb HTML and CSS Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the HTML and CSS Forum

All times are GMT -4. The time now is 4:31 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC