我正在尝试制作网页,但在使用 CSS 定位某些 HTML 元素时遇到问题。下面是我写的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<meta name = "description" content = "This is the homepage of this website">
<title>Home</title>
<style>
body{margin-top: 0px; background-color: #FBFBFB;}
.container{width: 1200px; margin-left: auto; margin-right: auto; margin-top : 0px; background-color: white; }
.header img{float: left; padding: 5px; background-color: orange;}
.header h1{font-size: 40px; font-family: "lucida console"; margin-left: 100px; letter-spacing: 1.2px; background-color: pink;}
.header p{color: gray; font-family: Verdana; font-size: 15px; letter-spacing: 1.4px; position: relative; top: 0px; left: 70px; background-color: lime;}
</style>
</head>
<body>
<div class = "container" >
<div class = "header">
<img src = "a.png" alt = "logo" width = "100" height = "100"></img>
<h1> Website name </h1>
<p><strong>- Tagline ,if any, goes here</strong></p>
</div>
</div>
</body>
</html>
这是我得到的输出
我想让标语部分更接近网站名称,我尝试将填充和边距更改为 0px 但没有运气。我怎样才能做到这一点 ?进一步如果我像这样引入边框
.header{border: 1px solid black;}
它将图像带到顶部,如下面的屏幕截图所示
为什么会这样?