关闭HTML标记 [英] Closing HTML tag

查看:89
本文介绍了关闭HTML标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么时候使用结束标记?斜线是否足够?

When is it appropriate to use a closing tag and when a slash is enough?

<div></div>

vs.

<div />

推荐答案

如果您的DOCTYPE设置为XHTML,则只能使用自闭标签<div />,因为它是从XML借来的,您可以在其中使用自闭标签.如果您的DOCTYPE设置为HTML 4.01或HTML 5,则无法使用它.

You can only use a self closing tag <div /> if your DOCTYPE is set to XHTML as this is borrowed from XML where you can have self closing tags. You can't have it if your DOCTYPE is set to HTML 4.01 or HTML 5.

http://www.w3.org/TR/xhtml1/

我不确定您是否确实希望使用此功能,但是,如果要清除浮点,则可以执行此操作,而不必担心兼容性问题,尤其是在IE进入仿真模式的情况下.

I'm not sure your exact use case for wanting this, but if it's for clearing floats, you can do this instead and not have to worry about compatibility issues, especially with IE if it kicks into emulation mode.

<style type="text/css">
.clear-fix {
    clear: both !important;
    display: block !important;
    font-size: 0 !important;
    line-height: 0 !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    list-style: none !important;
}
</style>
<br class="clear-fix" />

这篇关于关闭HTML标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆