vs
in clearing

2019-03-10 21:18发布

What is the difference

<br style="clear:both;"/>

vs

<div style="clear:both;"/>

??

Also, I thought

<div style="clear:both;"/> 

is a good way of clearing, but is

<div style="clear:both;"> </div>

a proper way?

标签: html xhtml
12条回答
【Aperson】
2楼-- · 2019-03-10 21:45

Well, there is no difference, depending on inherited styles.

This links says some more, and recommends : http://www.positioniseverything.net/easyclearing.html

查看更多
ら.Afraid
3楼-- · 2019-03-10 21:46

You do need to be careful about the / on the tag.

I had problems with the slash on the <script> tag terminated by <script language="javascript" src="MyScripts.js" /> way. Although, most xml compliant parsers would accept both.

<script> has to be terminated by </script>

查看更多
家丑人穷心不美
4楼-- · 2019-03-10 21:49

If you're writing (valid) XHTML you don't need to use the closing tag, but self closing div tags don't work in all browsers, so you should still use it. ie your example:

`<div style="clear:both;"> </div>`

This is valid XHTML (see html vs xhtml) but doesn't work in all browsers, so you should stick with the above:

<div style="clear:both;" />

also, For what it's worth the <br> tag is deprecated in favor of the <line> tag (see w3.org entry on the <br/> tag)

查看更多
孤傲高冷的网名
5楼-- · 2019-03-10 21:49

You could also use..


with added CSS rules it can do the job, and it serves this purpose.

查看更多
一夜七次
6楼-- · 2019-03-10 21:49

This is the style that I use for clearing:

.Clear { clear: both; height: 0; overflow: hidden; }

Usage:

<div class="Clear"></div>

This will not take up any extra space in the page as the height is zero.

Internet Explorer has a strange idea that the content of each element has to be at least one character high, and another strange idea that each element should be as high as it's content. Using overflow: hidden keeps the content from affecting the size of the element.

查看更多
老娘就宠你
7楼-- · 2019-03-10 21:50

<br /> is an inline element, where as <div> is a block element. Anyway, I personally prefer to use <hr class="clear">, I feel it is more semantically adequate.

查看更多
登录 后发表回答