html - 为什么 css 背景图片不显示

标签 html css

为什么当我在本地桌面上启动文件时没有显示 CSS 背景图像?这是我的代码:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" text="type/css" href="discovery.css">
<title>Programming Club Official Blog</title>
</head>
<body>
<h1>Programming Club Official Blog</h1>
<p>This is a blog that allows member of the programming club to keep in 
  touch about what we are doing in the club. Feel free to look at the code by pressing Ctrl-U! ~ Nathan Tran</p>
</body>
</html>

我的 CSS 代码:

html {
background:url (http://smashingyolo.com/wp-content/uploads/2014/05/Best- 
Website-Background-Images10.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
 background-size: cover;
}

我保证接受对我最有帮助的答案,所以请为我调试代码。感谢您的帮助!

最佳答案

有一些语法错误:

  1. 把链接放在引号里
  2. 去掉url和(
  3. 之间的空格

html {
background:url("http://smashingyolo.com/wp-content/uploads/2014/05/Best-Website-Background-Images10.jpg") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
 background-size: cover;
}
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" text="type/css" href="discovery.css">
<title>Programming Club Official Blog</title>
</head>
<body>
<h1>Programming Club Official Blog</h1>
<p>This is a blog that allows member of the programming club to keep in 
  touch about what we are doing in the club. Feel free to look at the code by pressing Ctrl-U! ~ Nathan Tran</p>
</body>
</html>

关于html - 为什么 css 背景图片不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40122324/

相关文章:

javascript - 如何在点击时使响应式 div 的背景图像变暗?

javascript - Twitter 时间轴不显示 HTML

javascript - 如何创建一个新的html元素?

html - 基于屏幕而不是页面的 CSS % 垂直居中加载 DIV

html - 列列表中的文本节点不考虑父宽度

css - 合并 TTF 字体文件(用于 CSS)

javascript - 代码在底部时是否需要 'onload'?

javascript - 循环播放背景 Youtube 视频

javascript - AngularJS,如何在 select > options 上使用 min =""来验证表单?

java - angularJS ng-dropdown-multiselect 实现无限滚动的滚动事件