我有以下的HTML代碼:當background-position:center指定背景圖像部分移出窗口時;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="1.css">
</head>
<body>
<body>
我的CSS代碼如下:
body {
background-image: url(tree.png);
background-repeat: no-repeat;
background-position: center;
}
現在我的谷歌Chrome瀏覽顯示以下的輸出:
這裏,圖像樹位於頂部中心,部分位於窗口外。
爲了改善這種情況我改變我的CSS代碼如下:
body {
background-image: url(tree.png);
background-repeat: no-repeat;
background-position: center;
margin-top: 600px;
}
現在我的瀏覽器顯示的輸出如下:
我的問題是,爲什麼我要補充保證金在頂部和背景圖像是不是默認去我的瀏覽器頁面的中心?
是什麼'vh'單位? – Sonevol
@Sonevol它的視口高度 – VilleKoo