html - 使用远程 url 的背景图像

标签 html css

我有这个简单的 html 页面

<html>
<head>
<meta charset="UTF-8">
<title>AlgoStash</title>
<style>
html { 
  background: url("<?php echo base_url('assets/sea.jpg');?>" no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

</style>
</head>
<body>
<audio src="<?php echo base_url('assets/avinu.mp3');?>" autoplay></audio>
</body>
<!-- אבא שלנו, המלך שלנו -->
</html>

生成此 html

<html>
<head>
<meta charset="UTF-8">
<title>AlgoStash</title>
<style>
html { 
  background: url("http://algopesa.com/assets/sea.jpg" no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

</style>
</head>
<body>
<audio src="http://algopesa.com/assets/avinu.mp3" autoplay></audio>
</body>
<!-- אבא שלנו, המלך שלנו -->
</html>

但是,页面不显示图像。

为什么这段代码

html { 
  background: url("http://algopesa.com/assets/sea.jpg" no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

虽然图像存在,但不产生背景图像?。我怎样才能使图像显示?。

最佳答案

您需要关闭url(...),否则将无法运行:

<html>
<head>
<meta charset="UTF-8">
<title>AlgoStash</title>
<style>
html { 
  background: url("<?php echo base_url('assets/sea.jpg');?>") no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

</style>
</head>
<body>
<audio src="<?php echo base_url('assets/avinu.mp3');?>" autoplay></audio>
</body>
<!-- אבא שלנו, המלך שלנו -->
</html>

关于html - 使用远程 url 的背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45756660/

相关文章:

在 chrome 中完成检查元素后,Jquery 工作

html - 如何在表中包含虚拟 tr 以设置列宽, "table-layout"设置为 "fixed"但高度为零

html - wordpress - 将相同的博客数据拉入多个站点

javascript - 如何使用 HTML/CSS 在网页中制作 Angular 文本

html - 带有溢出背景颜色的侧边栏

html - Bootstrap 缩略图未正确堆叠

html - 图片应该链接而不是背景

javascript - Angular JS 'route' 与 %2F 的组件不匹配(编码 '/' )

php - 查看个人资料页面 PHP

html - 打印时不要重复 TFOOT