gpt4 book ai didi

css - float 和 margin

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

我需要知道为什么下面的代码:

<!doctype html>
<html>
<head>
<title></title>
<style type="text/css">
*
{
margin:0px;
padding:0px;
}
#right
{
float:right;
}
#content
{
margin-top:20px;
}
</style>
</head>
<body>
<div id="right">a</div>
<div id="content">b</div>
</body>
</html>

在#right div 也应用 20px margin top。

最佳答案

缺少两件事:1)清晰:正确;在#content. 2) 需要指定宽度,以便您能够在没有 div 堆叠的情况下应用 clear:right。

<html>
<head>
<title></title>
<style type="text/css">
*
{
margin:0px;
padding:0px;
}
#right
{
float:right;
width:24%;
border:1px solid red;
}
#content
{
margin-top:20px;
width:74%;
clear: right;
border:1px solid aboue;
}
</style>
</head>
<body>
<div id="right">a</div>
<div id="content">b</div>
<div style="clear:both;"></div>
</body>
</html>

我添加了边框以便于查看。

关于css - float 和 margin ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3770133/

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