gpt4 book ai didi

HTML float 属性并排

转载 作者:行者123 更新时间:2023-11-28 03:11:58 25 4
gpt4 key购买 nike

我正在学习 HTML 和 CSS,并且我生成了关于 float 属性的代码。

	

body {
width: 750px;
font-family: Arial, Verdana, sans-serif;
color: #665544;
}

p {
width: 230px;
float: left;
margin: 5px;
padding: 5px;
background-color: #efefef;
}
<!DOCTYPE html>
<html>
<head>
<title>Using Float to Place Elements Side-by-Side</title>
</head>
<body>
<h1>The Evolution of the Bicycle</h1>
<p id="one">In 1817 Baron von Drais invented a walking machine that would help him get around the royal gardens faster.</p>
<p id="two">The device know as the Draisienne (or "hobby horse") was made of wood, and propelled by pushing your feed on the ground in a gliding movement.</p>
<p id="three">It was not seen a suitable for any place other than a well maintained pathway. </p>
<p id="four">In 1865, the velocipede (meaning "fast foot") attached pedals to the front wheel, but its wooden structure made it extremely uncomfortable. </p>
<p id="five">In 1870 the first all-metal machine appeared. The pedals were attached directly to the front wheel.
<p id="six">Solid rubber tires and the long spokes of the large front wheel provided a much smoother ride than its predecessor.</p>
</body>
</html>

现在,我的问题是 -

为什么第四段id="four"在第三段id="three"下面而不是移到左边边缘?

最佳答案

float: left; 将使用每一位可用的可用空间以确保没有空间被浪费。您可以在示例中看到这一点。第 3 列下方有空闲空间,因此第 4 列将自己放在那里。

我认为您正在寻找带有 vetical-align: top; 而不是 float: left;display: inline-block; code> 以获得不错的结果。请参见下面的示例。

			body {
width: 750px;
font-family: Arial, Verdana, sans-serif;
color: #665544;
}
p {
width: 230px;
margin: 5px;
padding: 5px;
background-color: #efefef;
display: inline-block;
vertical-align: top;
}
<!DOCTYPE html>
<html>
<head>
<title>Using Float to Place Elements Side-by-Side</title>
</head>
<body>
<h1>The Evolution of the Bicycle</h1>
<p id="one">In 1817 Baron von Drais invented a walking machine that would help him get around the royal gardens faster.</p>
<p id="two">The device know as the Draisienne (or "hobby horse") was made of wood, and propelled by pushing your feed on the ground in a gliding movement.</p>
<p id="three">It was not seen a suitable for any place other than a well maintained pathway. </p>
<p id="four">In 1865, the velocipede (meaning "fast foot") attached pedals to the front wheel, but its wooden structure made it extremely uncomfortable. </p>
<p id="five">In 1870 the first all-metal machine appeared. The pedals were attached directly to the front wheel.
<p id="six">Solid rubber tires and the long spokes of the large front wheel provided a much smoother ride than its predecessor.</p>
</body>
</html>

关于HTML float 属性并排,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45665321/

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