我正在嘗試製作網頁,但我無法使用CSS定位某些HTML元素。下面是我寫的代碼:無法使用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;}
它採用圖像上邊框如圖所示下面的截圖
這究竟是爲什麼?
你是怎麼改變'padding'和'margin'的? 'h1'還是'p'?它們都有默認的邊距,可能會導致這個間距。 – ASGM
是的,我嘗試設置邊距和填充h1,p和img爲0 px –