# 这段代码应该放在哪里用于顶部横幅？

**URL:** https://meta.discourse.org/t/where-shall-i-put-this-code-for-a-top-banner/300496
**Category:** Support
**Created:** [2024年三月22日 08:15 UTC](https://meta.discourse.org/t/where-shall-i-put-this-code-for-a-top-banner/300496 "2024-03-22T08:15:51Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Sherran](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sherran/32/267631_2.png) [@Sherran](https://meta.discourse.org/u/Sherran)
#### Post date: [2024年三月22日 08:15 UTC](https://meta.discourse.org/t/where-shall-i-put-this-code-for-a-top-banner/300496/1 "2024-03-22T08:15:51Z")

</div>

我有一个和这位老兄一样的问题：[How to add a header image and customize it](https://meta.discourse.org/t/how-to-add-a-header-image-and-customize-it/122242)

不知道该把这段代码放在哪里。有人能帮忙吗？

 ![image](https://global.discourse-cdn.com/meta/original/4X/e/1/6/e169734ac4cd9a4c15534a036da2e4b47771f5fe.png)

我只是把它放在这里，看起来我弄错了。

 ![image](https://global.discourse-cdn.com/meta/original/4X/6/7/a/67ad0d6418179f3dd5ac9e1160a415e35ca7289d.png)

或者有没有更简单的组件可以为我的 Discourse 添加一个横幅图片？

提前感谢。

---

<div class="post-metadata">

### Author: ![Moin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/moin/32/554653_2.png) [@Moin](https://meta.discourse.org/u/Moin)
#### Post date: [2024年三月22日 08:24 UTC](https://meta.discourse.org/t/where-shall-i-put-this-code-for-a-top-banner/300496/2 "2024-03-22T08:24:08Z")

</div>

您是否也安装了该主题中提到的 [https://meta.discourse.org/t/versatile-banner/109133？如果没有安装该组件，对该组件进行的调整将无效。](https://meta.discourse.org/t/versatile-banner/109133%EF%BC%9F%E5%A6%82%E6%9E%9C%E6%B2%A1%E6%9C%89%E5%AE%89%E8%A3%85%E8%AF%A5%E7%BB%84%E4%BB%B6%EF%BC%8C%E5%AF%B9%E8%AF%A5%E7%BB%84%E4%BB%B6%E8%BF%9B%E8%A1%8C%E7%9A%84%E8%B0%83%E6%95%B4%E5%B0%86%E6%97%A0%E6%95%88%E3%80%82)

---

<div class="post-metadata">

### Author: ![Sherran](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sherran/32/267631_2.png) [@Sherran](https://meta.discourse.org/u/Sherran)
#### Post date: [2024年三月25日 03:13 UTC](https://meta.discourse.org/t/where-shall-i-put-this-code-for-a-top-banner/300496/3 "2024-03-25T03:13:14Z")

</div>

是的，我安装并开始使用了。

---

<div class="post-metadata">

### Author: ![HAWK](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hawk/32/86627_2.png) [@HAWK](https://meta.discourse.org/u/HAWK)
#### Post date: [2024年三月25日 03:22 UTC](https://meta.discourse.org/t/where-shall-i-put-this-code-for-a-top-banner/300496/4 "2024-03-25T03:22:18Z")

</div>

您在哪里卡住了？

---

<div class="post-metadata">

### Author: ![Sherran](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sherran/32/267631_2.png) [@Sherran](https://meta.discourse.org/u/Sherran)
#### Post date: [2024年三月25日 03:26 UTC](https://meta.discourse.org/t/where-shall-i-put-this-code-for-a-top-banner/300496/5 "2024-03-25T03:26:24Z")

</div>

我想只使用多功能横幅来插入背景图片，但图片只显示了一点点。我需要输入文字才能显示更多内容，但我不需要文字。

---

<div class="post-metadata">

### Author: ![HAWK](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hawk/32/86627_2.png) [@HAWK](https://meta.discourse.org/u/HAWK)
#### Post date: [2024年三月25日 03:32 UTC](https://meta.discourse.org/t/where-shall-i-put-this-code-for-a-top-banner/300496/6 "2024-03-25T03:32:03Z")

</div>

信息太少，很难理解问题所在。您能否分享一些图片来展示出现什么问题？

---

<div class="post-metadata">

### Author: ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)
#### Post date: [2024年三月25日 03:33 UTC](https://meta.discourse.org/t/where-shall-i-put-this-code-for-a-top-banner/300496/7 "2024-03-25T03:33:35Z")

</div>

你好 @Sherran 👋 如果你只是想插入一个横幅图片，Vesatile 横幅组件可能不太合适。不妨看看这个主题：

> [@How do I add a giant header image?](https://meta.discourse.org/t/how-do-i-add-a-giant-header-image/62839):
>

或者看看 #Customization > Theme component 分类下的各种横幅组件

[https://meta.discourse.org/search?q=banner%20%23theme-component%20order%3Alatest\_topic](https://meta.discourse.org/search?q=banner%20%23theme-component%20order%3Alatest_topic)

---

<div class="post-metadata">

### Author: ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)
#### Post date: [2024年三月25日 04:59 UTC](https://meta.discourse.org/t/where-shall-i-put-this-code-for-a-top-banner/300496/8 "2024-03-25T04:59:56Z")

</div>

@Moin 刚刚提醒了我这件事：

> [@创建图像横幅](https://meta.discourse.org/t/create-a-an-image-banner/280279/2):
>
> 在主题组件中尝试此操作。在通用 CSS 中： #homepage-banner { width: 100%; height: 300px; } 您可以根据需要调整高度。 在通用横幅组件中，将以下内容放在图片周围，您可以在其中找到图片 URL，可能是在主标题内容字段中。 \<div id="homepage-banner"\> 将图片放在此处 \</div\> 您可以添加其他 CSS 代码以进行更多格式设置。您可以查看我网站上的通用横幅（请参阅个人资料），了解有关圆角和插入文本等其他格式设置的内容。

他们显然比我记性好 😛

---

<div class="post-metadata">

### Author: ![Sherran](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sherran/32/267631_2.png) [@Sherran](https://meta.discourse.org/u/Sherran)
#### Post date: [2024年三月25日 06:27 UTC](https://meta.discourse.org/t/where-shall-i-put-this-code-for-a-top-banner/300496/9 "2024-03-25T06:27:51Z")

</div>

我删除了所有列内容并插入了背景图片：

 ![image](https://global.discourse-cdn.com/meta/original/4X/2/b/2/2b2e84d29b790c95c778f7b8676affca4643b2f8.png)

但图片只显示成这样：

 ![image](https://global.discourse-cdn.com/meta/original/4X/f/f/5/ff513a87e2bab4c54c65d3598589b619be4b9bbc.png)

我想让它全尺寸显示。  
所以我尝试将支持人员或其他人提供的代码放在主题的 CSS 中（我不知道这是不是正确的位置。看起来不是。）

 ![image](https://global.discourse-cdn.com/meta/original/4X/7/6/c/76cc028ca27c69de4bee96a47c6d7c0fb31b84e8.png)

 ![image](https://global.discourse-cdn.com/meta/original/4X/d/9/4/d94881e8b41908f1529d64a531242872273334e3.png)

我不知道如何自定义 HTML。如果我有横幅图片的 URL，我该如何将其设为横幅？

---

<div class="post-metadata">

### Author: ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)
#### Post date: [2024年三月25日 14:35 UTC](https://meta.discourse.org/t/where-shall-i-put-this-code-for-a-top-banner/300496/10 "2024-03-25T14:35:26Z")

</div>

您看过我上面发布的链接吗？它有您的解决方案：

 ![image](https://global.discourse-cdn.com/meta/original/4X/8/9/e/89e44dadfc5820ea232b108e7391ed1ce1cc76bd.png)

---

<div class="post-metadata">

### Author: ![Sherran](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sherran/32/267631_2.png) [@Sherran](https://meta.discourse.org/u/Sherran)
#### Post date: [2024年三月27日 01:47 UTC](https://meta.discourse.org/t/where-shall-i-put-this-code-for-a-top-banner/300496/11 "2024-03-27T01:47:08Z")

</div>

谢谢。我会试试的。当你说使用这个 CSS 时，我不知道确切地应该把这个东西放在 {} 的哪里。让我看看。

---

<div class="post-metadata">

### Author: ![Sherran](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sherran/32/267631_2.png) [@Sherran](https://meta.discourse.org/u/Sherran)
#### Post date: [2024年三月27日 02:16 UTC](https://meta.discourse.org/t/where-shall-i-put-this-code-for-a-top-banner/300496/12 "2024-03-27T02:16:23Z")

</div>

CSS #homepage-banner 未生效。我更改了宽度和高度，但图片显示为全尺寸，没有任何变化。所以我把所有内容都写在了主标题内容里：

 ![image](https://global.discourse-cdn.com/meta/original/4X/5/e/1/5e1a90ed4af6b7f7620095c82e3b4b6cb45aa893.png)

但是图片会显示在主题内容中，而不是作为横幅显示。

 ![image](https://global.discourse-cdn.com/meta/original/4X/f/0/5/f052280b77b8a77d3bd44ac7d14b48ce541bf78d.jpeg)

关于 CSS 未生效。我这样写了。我应该改什么？

 ![image](https://global.discourse-cdn.com/meta/original/4X/6/2/d/62dd5e7fff266145eee5aba7dbd62437b8cdbac1.png)

我不太擅长编码和 HTML。我一定遗漏了什么。希望得到您的帮助。先谢谢您了。
