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

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

Add background image to quarto website home page

问题

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

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

  1. project:
  2. type: website
  3. website:
  4. title: &quot;Sunset Sea&quot;
  5. navbar:
  6. background: transparent
  7. left:
  8. - text: Home
  9. href: &quot;index.html&quot;
  10. - text: Report
  11. href: &quot;report.html&quot;
  12. page-footer:
  13. border: false
  14. background: transparent
  15. foreground: DimGray
  16. left: Left content
  17. right: Right content
  18. format:
  19. html:
  20. theme: &quot;styles.css&quot;

index.qmd

  1. ---
  2. format: html
  3. ---
  4. # Sunset Sea
  5. Welcome to Sunset Sea.

report.qmd

  1. ---
  2. title: &quot;Report&quot;
  3. format: html
  4. ---
  5. ## Heading 1
  6. This is a report

styles.css

  1. /*-- scss:defaults --*/
  2. body {
  3. background-image: url(&quot;https://images.pexels.com/photos/189349/pexels-photo-189349.jpeg&quot;);
  4. background-size: cover;
  5. background-repeat: no-repeat;
  6. /*background-position: center center;*/
  7. /*background-attachment: fixed;*/
  8. }

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

  1. format:
  2. html:
  3. theme: &quot;styles.css&quot;
  4. include-before-body: before.html
  5. include-after: after.html

before.html

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

after.html

  1. &lt;/div&gt;

Update styles.css*

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

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

Quarto 1.2.1

答案1

得分: 2

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

index.qmd

  1. ---
  2. format: html
  3. ---
  4. <style>
  5. body {
  6. background-image: url("https://images.pexels.com/photos/189349/pexels-photo-189349.jpeg");
  7. background-size: cover;
  8. background-repeat: no-repeat;
  9. }
  10. </style>
  11. # 日落海景
  12. 欢迎来到日落海景。

style.css

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

  1. /*-- scss:defaults --*/

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


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


  1. <details>
  2. <summary>英文:</summary>
  3. **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**.
  4. **index.qmd**
  5. ~~~
  6. ---
  7. format: html
  8. ---
  9. &lt;style&gt;
  10. body {
  11. background-image: url(&quot;https://images.pexels.com/photos/189349/pexels-photo-189349.jpeg&quot;);
  12. background-size: cover;
  13. background-repeat: no-repeat;
  14. }
  15. &lt;/style&gt;
  16. # Sunset Sea
  17. Welcome to Sunset Sea.
  18. ~~~
  19. **style.css**
  20. (do not specify the background images in the style.css)
  21. ~~~
  22. /*-- scss:defaults --*/
  23. ~~~
  24. &lt;hr&gt;
  25. [![home page with background image][1]][1]
  26. &lt;hr&gt;
  27. [![Report page with no background image][2]][2]
  28. &lt;hr&gt;
  29. [1]: https://i.stack.imgur.com/NhQj3.jpg
  30. [2]: https://i.stack.imgur.com/BRVvV.png
  31. </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:

确定