gpt4 book ai didi

html - 需要有关 css float 的帮助

转载 作者:太空宇宙 更新时间:2023-11-04 04:48:04 24 4
gpt4 key购买 nike

当段落和 img 都 float 时,为什么只有段落的第一行出现在左侧,所有其他行都出现在图像下方?这是代码..

    <!DOCTYPE html>
<html>
<head>
<style>
img,p
{
float:left;
}
</style>
</head>

<body>
<img src="logocss.gif" width="95" height="84" />
<p>
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>

但是当只有 img float 时一切正常,即所有文本都出现在左侧

最佳答案

EXAMPLE

试试这段代码:

<img src="logocss.gif" width="95" height="84" />
<p style="width:300px;">
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>​

您的代码不起作用,因为元素 p 没有宽度

如果 float 元素没有预先定义的宽度,它将占用所需和可用的尽可能多的水平空间,而不管 float 。注意:一些浏览器试图在未定义宽度时将元素放置在 float 元素旁边——通常只给非 float 元素提供少量空间。因此,您应该始终在 float 元素上定义宽度。

关于html - 需要有关 css float 的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14052743/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com