tags:

views:

320

answers:

5

What is considered "better" practice:

<div class="clr"></div> (Where clr is clear:both) or just simply:

<BR CLEAR:BOTH />

I'm really confused since I was once told never to use BR but then BR is designed to be what the div class is?

Question:

Would it be wrong to just use <BR /> when you want to clear or should I use the div?

Thanks in advance

edit: I've already read http://www.w3.org/TR/html4/appendix/notes.html#notes-line-breaks and http://www.w3.org/TR/html4/struct/text.html#edef-BR

example (note I've removed classes and added the style directly to the html for ease of reading):

<div style="float:left;">
    <a href="www.example.com"><img style="float:left;" src="/images/videos/video.jpg" width="90" height="75" alt="thumb" title="title" /></a>
    <a href="www.example.com" >Title text</a>
    <div style="clear:right;"></div>
    <span>Length: duration here</span>
    <div style="clear:right;"></div>
    <span>descriptive text here<span>
    <div style="clear:right;"></div>
    <span>Date: date of added here</span>
</div>

In your expert opinions am I using spans, divs, etc correctly? Should I use BR's instead of Divs for the breaks.

Thanks everyone

Closing Note:

Thank you for all for pointing out that a linebreak is nothing to do with clearing of floats. I need to learn exactly what a linebreak is... I guess I don't know.

Thanks to freddy for seeing what I actually wanted to do and giving me the solution I clumsily asked for.

+5  A: 

None of the above. Best practice is to use the HTML to give structure to the information.

So, you use div to put a section of information in the page. If you need a line break after that information, you use CSS to style that.


<div id="someinformation">
   <p>some parragraph of info</p>
   <ul>
      <li>an item of the list</li>
      <li>another item</li>
      <li>yet another item</li>
   </ul>
</div>

Now in CSS you can style as needed. The document on its own have structured information with some default way of being rendered by the browsers. The structure plays well with screen readers which are not bothered with HTML elements for visual appearance.

Say you have more elements, in CSS you can decide to let them appear beside each other, or with a line break, or with some margins.

eglasius
Sorry, I'm not sure I understand you. Could you please explain again?
Dorjan
posted an update, I hope it helps. search around for semantic HTML and XHTML.
eglasius
hmm... what I am trying to achieve is an image to the left, and the info to the right. In your example I could float the image to the left, and have the UL set which will go down the right? And no need for extra clears either?Or am I off the ball?
Dorjan
Yes, I am assuming you do that in a separate .css file. You can also do it in a <style> section. Its not recommended to make it inline in the document. In my specific example, I could apply float:left; to "#someinformation p", and float:right to "#someinformation ul". For it to work well you want to set a width for those elements (might be a %), so they use the space you intend them to and the browser knows how to calculate the layout.
eglasius
Hey Freddy! Your solution not only looks the best but feels it too. I replaced the spans and div's with an UL and restyled it and guess what, exactly what I needed.Thanks a bunch, I guess I should use lists more when I'm listing stuff. +1
Dorjan
+2  A: 

You're asking the wrong question for the solutions you gave yourself. Those 'clear' elements aren't there to create line breaks usually, they are there to clear floated elements that occur before them.

Steerpike
so a line break isn't the same as a clear in what way? I thought all the BR did was applying the Clear:both style?
Dorjan
`<br/>` will insert a linebreak that has nothing to do with clearing floats
knittl
@Dorjan: BR also creates a line break, a DIV technically does not.
Dmitri Farkov
oh right. I need to learn what a line break is then
Dorjan
The problem is his question title conflicts with his displayed solutions. If you're trying to create a linebreak then you should use <br /> if you're trying to clear floats (which is what his examples are doing) then you should use a div or preferably one of the other solutions for clearing
Steerpike
A: 

I'd never use a div for that. I believe that <br/> is the best thing to do when you need a line break inside a <p> for example. Anyway, I'm not sure why are you using that CLEAR:BOTH or the class=clr.

Santi
I think you left your example code outside of the code tags for stackoverflow as I can't see them
Dorjan
A: 

What about adding clear-properties to your span elements, instead of inserting another (pointless) element in there?

HTML should describe structure, not presentation. If you add BR - line breaks - to change the presentation (how the site looks when styled) you're doing something wrong.

Adding DIVs or SPANs has no effect on the structure, since they have no semantic meaning at all.

Arve Systad
When you add clear to an element it clears before itself right? not after?That is what I felt about all these extra elements, It feels wasteful I just didn't know another way...
Dorjan
@Arve I agree with the overall argument you say, but I wouldn't say DIV is worthless. It exists to mark a section of information in your document. Its wrong using it just to cause a visual behavior, but its not wrong to use it to adequately group the information in your document.
eglasius
Adding clear's to spans seem to do nothing... I guess they don't accept it?
Dorjan
@Freddy: Im not saying Divs are worthless - they are really important! They just have no proper semantic meaning like P, TABLE or other structural elements.@Dorjan: Floating and then clearing with your spans should fix it. Or putting them in a list, of course.
Arve Systad
eglasius
+1  A: 

BR are used semantically for adding line breaks in such places as in the middle of a phrase or between two words. It does NOT clear floats.

An element with a clear property clears floats on either side specified above the element, here it makes more sense semantically to use a div - since you are not creating a line break but rather clearing a float.

a BR can be specified to have a clear but semantically once again, this would lack sense.

For adding padding/break/margin after a certain text it is best to use the margin/padding properties rather than use BR's consecutively.

So in summary:

This is the first line<br />Second line

For br's.

<div style="float: left">Clear me</div>
<div style="clear:left"></div>

For div's.

<div style="margin-bottom: 19px;">Test here</div>

For a "line-break" or more accurately margin under the text.

As to your presentation, it seems that you may want to research floats a bit more. Semantically it is a bit messy with the fact everything is float left, and then you clear right every line. Graceful coding is all about minimal code - maximum results.

Dmitri Farkov
Thanks for the tips Dmitri +1
Dorjan