小码哥的IT人生

HTML <br> 标签的 clear 属性 详解

HTML基础 2023-07-12 15:04:02小码哥的IT人生shichen

HTML <br> 标签的 clear 属性

通常情况下,<br> 标签会告诉浏览器立即停止当前的文本流,并在下一行的左边,或者在左对齐的内联图形或表格的右边开始继续输出文本流。

但是有时候,您也许希望当前的文本流在当前左边或右边的内联表格或图像的下面一行继续输出。

HTML 4 和 XHTML 通过 <br> 标签提供了这样的功能。它可以具有三个值:left、right 或者 all,每个值都代表一个边界或两边的边界。当指定的边界没有图像时,浏览器才会继续输出文本。

提示和注释

提示:一般情况下,文本流中的其他行会在内联图像的底部显示,除非图形的 <img> 标签被设置为左对齐或右对齐(对于 <table> 标签也一样)。因此,<br> 标签的 clear 属性只对这些左对齐或右对齐的图像或表格起作用。

TIY

完整实例【不带有 align 属性的 <img> 标签与带有 clear 属性的 <br> 标签】:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<img src="/i/eg_greanfoliage.jpg" />
This text should wrap around the image, flowing between the image and the right margin of the document.
<br />
This text will flow as well, but will be below the image, extending across the full width of the page. there will be whitespace above this text and to the right of the image.
</body>
</html>

可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html

完整实例【带有 align 属性的 <img> 标签与不带有 clear 属性的 <br> 标签】:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<img src="/i/eg_greanfoliage.jpg" align="left" />
This text should wrap around the image, flowing between the image and the right margin of the document.
<br />
This text will flow as well, but will be below the image, extending across the full width of the page. there will be whitespace above this text and to the right of the image.
</body>
</html>

可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html

完整实例【带有 align 属性的 <img> 标签与带有 clear 属性的 <br> 标签】:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<img src="/i/eg_greanfoliage.jpg" align="left" />
This text should wrap around the image, flowing between the image and the right margin of the document.
<br clear="left" />
This text will flow as well, but will be below the image, extending across the full width of the page. there will be whitespace above this text and to the right of the image.
</body>
</html>

可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html

完整实例【align 属性为 absmiddle 的 <img> 标签与clear 属性为 left 的 <br> 标签】:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<img src="/i/eg_greanfoliage.jpg" align="absmiddle" />
This text should wrap around the image, flowing between the image and the right margin of the document.
<br clear="left" />
This text will flow as well, but will be below the image, extending across the full width of the page. there will be whitespace above this text and to the right of the image.
</body>
</html>

可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html

版权所有 © 小码哥的IT人生
Copyright © phpcodeweb All Rights Reserved
ICP备案号:苏ICP备17019232号-2  

苏公网安备 32030202000762号

© 2021-2024