我正在尝试为我的页面制作背景,我希望它出现在中间。但出于某种原因,无论我做什么,它都显示在左侧。
body
{
font-family:Tahoma, Geneva, sans-serif;
font-size:12px;
color:#696969;
text-align:center;
min-width:320px;
background:url(../images/background.jpg) center no-repeat;
position:relative;
-webkit-text-size-adjust: none;
}
我创建了一个单独的文件,它显示在中间,代码如下:
<style>
body{
background:url('background.jpg') center no-repeat;
}
</style>
为什么它在我的原始页面上不起作用?有什么建议吗?
最佳答案
在测试了你的两种方法之后,我得到了它:
// style.css
body
{
font-family:Tahoma, Geneva, sans-serif;
font-size:12px;
color:#696969;
text-align:center;
min-width:320px;
background:url(bg.jpg) center top no-repeat;
position:relative;
-webkit-text-size-adjust: none;
}
// index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
<link href="style.css" rel="stylesheet">
</head>
<body>
</body>
</html>
这是我的输出:
(图片是从谷歌搜索中随机选择的)
希望这对您有所帮助!
关于html - 我不能让正文背景出现在没有重复的中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18810817/