html - CSS 中的两个背景图像

标签 html css

<分区>

我正在尝试在 CSS 中添加两个背景,但一个图像填充整个背景,另一个图像在页面的右中央对齐。这是我当前样式表的一部分:

body {
  font-family: 'Nunito', sans-serif;
  color: #384047;
  background-image: url(http://footyprofit.co/wp-content/uploads/2013/02/golf-background.jpg);
  background-color: #cccccc;
  background-position: center;
  background-repeat: no-repeat;
  -webkit-background-size: cover;
}

我试过用逗号分隔 URL,然后用逗号分隔定位,但这不起作用。有任何想法吗?

最佳答案

将父元素的高度设置为 100%,即设置为 html。然后使用 background-sizecover 值来占据底层图像的整个空间。将 right center 设置为第一张图片的“background-position”。

html,
body {
  height: 100%;
}
body {
  background-image: url("http://placehold.it/300x300/333"), url("http://placehold.it/1200x1200");
  background-position: right center, center center;
  background-repeat: no-repeat;
  background-size: auto auto, cover;
  color: #384047;
  font-family: "Nunito", sans-serif;
  height: 100%;
}

关于html - CSS 中的两个背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31267646/

相关文章:

jquery - Ajax 不会让 css 当前链接样式正常工作

javascript - HTML - 保留用户填写的字段并在 "submitted"时显示在下一页上

html - 按钮文本与查询字符串中提交的值不同

html - 使用纯 CSS 在具有固定纵横比的框中垂直居中内容?

javascript - 如何在 Extjs 中更改 Treepanel 中访问的节点颜色,就像我们在 html 中一样

html - 元素上的 CSS Margin-Top

jquery - 如果文档在 30 天内未更新,如何取消突出显示文本

html - XPath:定位文本节点包含两个字符串的元素

html - CSS 悬停效果和覆盖

html - 像表格一样显示嵌套列表