gpt4 book ai didi

css - 为什么 margin-right 不起作用,而 margin-left、margin-top 和 margin-bottom 却起作用?

转载 作者:太空狗 更新时间:2023-10-29 12:33:03 26 4
gpt4 key购买 nike

当我设置 margin-right: 50px;我没有看到任何效果,但是当我替换 margin-right: 50px; 时左边距:50px;或 margin-top: 50px;我确实看到了效果。这是带有 margin-right 的代码...

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Max Pietsch homepage</title>
<style type="text/css">
.me {
margin-right: 20px;
}
#pic_of_me {
width: 200px;
}
</style>
</head>
<body>
<div class="me">
<img id="pic_of_me" src="me.jpg" alt="A picture of me">
</div>
</body>

最佳答案

HTML 元素默认总是在其父元素的左上角对齐

因此,您的 .me 位于 body 元素的左上角。

如果您添加 margin-topmargin-left 您的 .me 会将自己“推”离这个 Angular (这就是为什么你看到它在移动)。

如果您添加 margin-rightmargin-bottom,您元素右侧/下方的其他元素将被“推”开。

由于您的元素右侧/下方没有任何元素,因此您看不到这种效果。

试试吧!

关于css - 为什么 margin-right 不起作用,而 margin-left、margin-top 和 margin-bottom 却起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32598727/

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