一个浮动元素可以尽可能向左或向右移动。简单来说,这意味着浮动元素可以显示在最左侧或最右侧。
浮动元素之后的元素将在其周围流动。
浮动元素之前的元素不会受到影响。
如果图像向右浮动,则文本在其周围向左流动;如果图像向左浮动,则文本在其周围向右流动。
属性 | 说明 | 值 |
clear | clear属性用于避免在周围流动的浮动元素之后的元素。 | 左,右,两者都不继承 |
float | 它指定元素是否浮动。 | 左,右,无,继承 |
值 | 说明 |
none | 它指定该元素不是浮点型的,并且将显示在文本中刚出现的位置。这是默认值。 |
left | 用于将元素向左浮动。 |
right | 用于将元素向右浮动。 |
initial | 它将属性设置为其初始值。 |
inherit | 它用于从其父元素继承此属性。 |
<!DOCTYPE html>
<html>
<head>
<style>
img {
float: right;
}
</style>
</head>
<body>
<p>下一段包含具有样式的图像
<b>float:right</b>. 结果是图像将浮动到该段落的右侧。</p>
<img src="good-morning.jpg" alt="Good Morning Friends"/>
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</p>
</body>
</html>