在Quarto网站首页添加背景图片。

huangapple go评论56阅读模式
英文:

Add background image to quarto website home page

问题

要在 quarto 网站的首页上添加背景图像,但不在报告页面上添加背景图像,你可以尝试以下解决方案:

  1. 首先,更新 styles.css 文件如下,以将背景图像应用于 .splash 类:
.splash {
  background-image: url("https://images.pexels.com/photos/189349/pexels-photo-189349.jpeg");
  background-size: cover;
  background-repeat: no-repeat;
}
  1. _quarto.yml 中添加 include-before-bodyinclude-after 部分,以在首页上添加一个包含背景图像的 div,并在报告页面上不添加:
format:
  html:
    theme: "styles.css"
    include-before-body: before.html
    include-after: after.html
  1. 创建 before.html 文件,该文件包含以下内容:
<div class="splash">
  1. 创建 after.html 文件,该文件包含以下内容:
</div>

这将在网站首页上添加背景图像,但不会在报告页面上添加。运行 quarto preview 以查看效果。

请注意,这只会在网站首页上应用背景图像,而不会在其他页面上应用。

英文:

In a quarto website, how do I add a background image filling the entire page but only to the home page?

I have a working solution which adds the background correctly, but does it across the entire website. In the example below, I do not want the report page to have the background image. It should have a plain white background, navbar and footer.

Reproducible example. Creating the following files:

_quarto.yml

project:
  type: website

website:
  title: &quot;Sunset Sea&quot;
  navbar:
    background: transparent
    left:
      - text: Home
        href: &quot;index.html&quot;
      - text: Report
        href: &quot;report.html&quot;
  page-footer:
    border: false
    background: transparent
    foreground: DimGray
    left: Left content
    right: Right content

format:
  html:
    theme: &quot;styles.css&quot;

index.qmd

---
format: html
---

# Sunset Sea

Welcome to Sunset Sea.

report.qmd

---
title: &quot;Report&quot;
format: html
---

## Heading 1

This is a report

styles.css

/*-- scss:defaults --*/

body {
  background-image: url(&quot;https://images.pexels.com/photos/189349/pexels-photo-189349.jpeg&quot;);
  background-size: cover;
  background-repeat: no-repeat;
  /*background-position: center center;*/
  /*background-attachment: fixed;*/
}

Run quarto preview

在Quarto网站首页添加背景图片。

Possibly a solution is to add a div just before or after the body div with a specific class only on the home page and target that class with css. I am not quite sure how to go about doing that.

I have tried include-before-body but that does not cover navbar and footer anyway.

Updated part of _quarto.yml

format:
  html:
    theme: &quot;styles.css&quot;
    include-before-body: before.html
    include-after: after.html

before.html

&lt;div class=&quot;splash&quot;&gt;

after.html

&lt;/div&gt;

Update styles.css*

.splash {
  background-image: url(&quot;https://images.pexels.com/photos/189349/pexels-photo-189349.jpeg&quot;);
  background-size: cover;
  background-repeat: no-repeat;
}

在Quarto网站首页添加背景图片。

Quarto 1.2.1

答案1

得分: 2

index.qmdReport.qmd 将生成两个不同的网页。因此,如果您想为 index.html 添加特定样式,请直接在 index.qmd 中定义 CSS 样式(在 style 标签内),而不是在 style.css 中。

index.qmd

---
format: html
---

<style>
  body {
    background-image: url("https://images.pexels.com/photos/189349/pexels-photo-189349.jpeg");
    background-size: cover;
    background-repeat: no-repeat;
  }
</style>

# 日落海景

欢迎来到日落海景。

style.css

(请不要在 style.css 中指定背景图像)

/*-- scss:defaults --*/

在Quarto网站首页添加背景图片。


在Quarto网站首页添加背景图片。



<details>
<summary>英文:</summary>

**index.qmd** and **Report.qmd** will generate two different webpages. So if you want to add any style specific to **index.html** define the css styles (within `style` tag) in the **index.qmd** directly, instead of **style.css**.

**index.qmd**

~~~
---
format: html
---

&lt;style&gt;
  body {
  background-image: url(&quot;https://images.pexels.com/photos/189349/pexels-photo-189349.jpeg&quot;);
  background-size: cover;
  background-repeat: no-repeat;
}
  
&lt;/style&gt;


# Sunset Sea

Welcome to Sunset Sea.
~~~

**style.css**

(do not specify the background images in the style.css)

~~~
/*-- scss:defaults --*/

~~~

&lt;hr&gt;

[![home page with background image][1]][1]

&lt;hr&gt;

[![Report page with no background image][2]][2]

&lt;hr&gt;


  [1]: https://i.stack.imgur.com/NhQj3.jpg
  [2]: https://i.stack.imgur.com/BRVvV.png

</details>



huangapple
  • 本文由 发表于 2023年3月3日 23:08:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75628760.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定