css 在Jekyll主题的标题中插入覆盖内容

t1qtbnec  于 2023-05-30  发布在  其他
关注(0)|答案(1)|浏览(191)

我想添加覆盖内容的标题,特别是覆盖在顶部的标题图像。

详情

我已经写了HTML/Liquid和SCSS,当我在网站构建之外测试它时,它都能正常工作,但我想知道如何使用_masthead.html将此覆盖内容添加到所有页面的标题中。我们的目标是插入一个具有可变内容的 widget。这是标题当前在站点上的样子image of website header这是它应该看起来的样子image of website header

现在的样子

在我实现Christian告诉我的内容后,它现在看起来像这样x1c 0d1x

文件

该存储库可以找到here,其组件包括:
这就是_masthead.html

  1. {% if page.header == NULL and page.header.image_fullwidth == NULL and page.header.pattern == NULL and page.header.background-color == NULL and page.header.title == NULL %}
  2. <div id="masthead-no-image-header">
  3. <div class="row">
  4. <div class="small-12 columns"><!-- <a id="logo" href="{{ '/' | absolute_url }}" title="{{ site.title }} – {{ site.slogan }}">
  5. <img src="{{ site.url }}{{ site.baseurl }}/assets/img/{{ site.logo }}" alt="{{ site.title }} – {{ site.slogan }}">
  6. </a> -->
  7. </div>
  8. <!-- /.small-12.columns -->
  9. </div>
  10. <!-- /.row -->
  11. </div>
  12. <!-- /#masthead -->
  13. {% if page.breadcrumb == true %}
  14. {% include _breadcrumb.html %}
  15. {% endif %}
  16. {% elsif page.header.title %}
  17. <div id="masthead-with-text" style="{% if page.header.background-color %}background: {{ page.header.background-color }};{% endif %} {% if page.header.image_fullwidth %}{% elsif page.header.pattern %}background: linear-gradient(rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.4)), url('{{ site.urlimg }}/{{ page.header.pattern }}'){% endif %}">
  18. <div class="row">
  19. <div class="small-12 columns">
  20. <div class="masthead-title">{{ page.header.title }}</div>
  21. </div>
  22. <!-- /.small-12.columns -->
  23. </div>
  24. <!-- /.row -->
  25. </div>
  26. <!-- /#masthead -->
  27. {% if page.breadcrumb == true %}
  28. {% include _breadcrumb.html %}
  29. {% endif %}
  30. {% if page.header.caption_url && page.header.caption %}
  31. <div class="masthead-caption">
  32. <a href="{{ page.header.caption_url }}">{{ page.header.caption }}</a>
  33. </div>
  34. {% elsif page.header.caption %}
  35. <div class="masthead-caption">
  36. {{ page.header.caption }}
  37. </div>
  38. {% endif %}
  39. {% elsif page.header.image_fullwidth %}
  40. <div id="masthead">
  41. <div class="row">
  42. {% if page.header_widget %}
  43. {% include _header-widget.liquid %}
  44. {% endif %}
  45. <div class="small-12 columns"><!-- <a id="logo" href="{{ '/' | absolute_url }}" title="{{ site.title }} – {{ site.slogan }}">
  46. <img src="{{ site.url }}{{ site.baseurl }}/assets/img/{{ site.logo }}" alt="{{ site.title }} – {{ site.slogan }}">
  47. </a> -->
  48. </div>
  49. <!-- /.small-12.columns -->
  50. </div>
  51. <!-- /.row -->
  52. </div>
  53. <!-- /#masthead -->
  54. {% if page.breadcrumb == true %}
  55. {% include _breadcrumb.html %}
  56. {% endif %}
  57. {% if page.header.caption_url && page.header.caption %}
  58. <div class="masthead-caption">
  59. <a href="{{ page.header.caption_url }}">{{ page.header.caption }}</a>
  60. </div>
  61. {% elsif page.header.caption %}
  62. <div class="masthead-caption">
  63. {{ page.header.caption }}
  64. </div>
  65. {% endif %}
  66. {% elsif page.header.pattern %}
  67. <div id="masthead-with-pattern" style="background: url('{{ site.urlimg }}/{{ page.header.pattern }}')">
  68. <div class="row">
  69. <figure class="small-12 columns">
  70. <img src="{{ site.urlimg }}/{{ page.header.image }}" alt="{{ site.title }}">
  71. </figure>
  72. <!-- /.small-12.columns -->
  73. </div>
  74. <!-- /.row -->
  75. </div>
  76. <!-- /#masthead -->
  77. {% if page.breadcrumb == true %}
  78. {% include _breadcrumb.html %}
  79. {% endif %}
  80. {% if page.header.caption_url && page.header.caption %}
  81. <div class="masthead-caption">
  82. <a href="{{ page.header.caption_url }}">{{ page.header.caption }}</a>
  83. </div>
  84. {% elsif page.header.caption %}
  85. <div class="masthead-caption">
  86. {{ page.header.caption }}
  87. </div>
  88. {% endif %}
  89. {% elsif page.header.background-color %}
  90. <div id="masthead-with-background-color" style="background: {{ page.header.background-color }};">
  91. <div class="row">
  92. <figure class="small-12 columns">
  93. <img src="{{ site.urlimg }}/{{ page.header.image }}" alt="{{ site.title }}">
  94. </figure>
  95. <!-- /.small-12.columns -->
  96. </div>
  97. <!-- /.row -->
  98. </div>
  99. <!-- /#masthead -->
  100. {% if page.breadcrumb == true %}
  101. {% include _breadcrumb.html %}
  102. {% endif %}
  103. {% if page.header.caption_url && page.header.caption %}
  104. <div class="masthead-caption">
  105. <a href="{{ page.header.caption_url }}">{{ page.header.caption }}</a>
  106. </div>
  107. {% elsif page.header.caption %}
  108. <div class="masthead-caption">
  109. {{ page.header.caption }}
  110. </div>
  111. {% endif %}
  112. {% elsif page.header == false %}
  113. {% if page.breadcrumb == true %}
  114. {% include _breadcrumb.html %}
  115. {% endif %}
  116. {% endif %}

这就是header-widget.scss

  1. @import "/assets/fonts/imports.css";
  2. // @import url(https://raw.githubusercontent.com/NewSpectrum/Technovine-Site/main/_sass/foundation-components/_header-button.scss)
  3. //▸ Widget Properties
  4. $header-color: hsl(0deg, 0%, 100%);
  5. $txt-color: hsl(0deg, 0%, 100%);
  6. $inner-shadow: inset 2px 2px 5px hsla(0deg, 0%, 0%, 0.5);
  7. $txt-shadow: 0.5px 0.5px 5px hsla(0deg, 0%, 0%, 0.5);
  8. $widget-bg-color: hsla(0deg, 0%, 0%, 0.5);
  9. $widget-padding: 1rem 2.5rem 2rem 2.5rem;
  10. //▸ Button Properties
  11. $sr-bg: hsl(
  12. 18deg,
  13. 100%,
  14. 62%
  15. );
  16. $button-text: hsl(0deg, 0%, 100%);
  17. $button-gr1: hsl(18deg,
  18. 100%, 62%);
  19. // #ff773d
  20. $button-gr2: hsl(18deg, 80%, 45%);
  21. // #cf4e17
  22. $box-shadow: 1px 1px 3px hsla(0, 0%, 0%, 50%);
  23. $text-shadow: 0.5px 0.5px 1.5px hsla(0, 0%, 0%, 50%);
  24. $button-gradient: linear-gradient(
  25. 135deg,
  26. $button-gr1 0%,
  27. $button-gr2 100%
  28. );
  29. .header-widget {
  30. position: relative;
  31. align-items: left;
  32. max-width: 1000px;
  33. margin-left: auto;
  34. margin-right: auto;
  35. .widget-container {
  36. background-color: $widget-bg-color;
  37. padding: $widget-padding;
  38. border-radius: 20px;
  39. backdrop-filter: blur(10px);
  40. -webkit-backdrop-filter: blur(10px);
  41. box-shadow: $inner-shadow;
  42. h1,
  43. h2,
  44. h3,
  45. h4,
  46. h5,
  47. h6 {
  48. font-family: "Libre Baskerville", serif;
  49. color: $header-color;
  50. }
  51. p {
  52. font-family: "Lato", sans-serif;
  53. font-size: 1rem;
  54. color: $txt-color;
  55. }
  56. }
  57. }
  58. .button-container {
  59. position: relative;
  60. max-width: 200px;
  61. font-family: "Lato", sans-serif;
  62. text-shadow: $text-shadow;
  63. background: $button-gradient;
  64. color: $button-text;
  65. border: 0;
  66. box-shadow: $box-shadow;
  67. border-color: hsla(0, 0%, 0%, 0%);
  68. border-radius: 20px;
  69. padding: 10px 20px;
  70. a {
  71. color: inherit;
  72. text-decoration: none;
  73. }
  74. }

这是header-widget-button.html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Button Test</title>
  7. <link rel="stylesheet" href="../css/_header-button.css">
  8. <script id="service-request_script"
  9. src="../js/service-request_button.js"></script>
  10. <script id="slideshow">
  11. // JavaScript
  12. // Change 'background-image' in 'body' (css)
  13. // Change <section> content
  14. </script>
  15. </head>
  16. <body>
  17. <section id="header-widget" class="header-widget">
  18. <div id="sales-widget" class="widget-container">
  19. <h1>
  20. Worry-Free Professional IT Services
  21. </h1>
  22. <p>
  23. No need to worry about amateur service. Get the IT professionals your business needs.
  24. </p>
  25. <!--BUTTON-->
  26. <br /><br />
  27. <div id="button-container" class="sales-request button">
  28. <button id="sales_button" onclick="requestService()">
  29. Get&nbsp;Quote
  30. </button>
  31. </div>
  32. </div>
  33. <br><br>
  34. <div id="service-request_widget" class="widget-container">
  35. <h1>
  36. Worry-Free Professional IT Services
  37. </h1>
  38. <p>
  39. No need to worry about amateur service. Get the IT professionals your business needs.
  40. </p>
  41. <!--BUTTON-->
  42. <br /><br />
  43. <div id="button-container" class="sales-request button">
  44. <button id="sales_button" onclick="requestService()">
  45. Submit&nbsp;Ticket
  46. </button>
  47. </div>
  48. </div>
  49. </section>
  50. </body>
  51. </html>

这是header-widget.liquid

  1. <section id="header-widget" class="widget-container">
  2. <div id="sales-widget" class="header-widget">
  3. {% if page.header_widget:widget_title %}
  4. <h1>
  5. {{ page.header_widget:widget_title }}
  6. </h1>
  7. {% else %}
  8. <code>widget_title is not set</code>
  9. {% endif %}
  10. <p>
  11. {{ page.header_widget:widget_text }}
  12. </p>
  13. <!--BUTTON-->
  14. <br /><br />
  15. <div id="button-container" class="button-container">
  16. <button id="sales_button" onclick="requestService()">
  17. <a href="{{ page.header_widget:button_url }}">
  18. {{ page.header_widget:button_text }}
  19. </a>
  20. </button>
  21. </div>
  22. </div>
  23. </section>

这是index.md

  1. header:
  2. image_fullwidth: networking-connections-004.jpeg
  3. header_widget:
  4. widget_title: "Worry-Free Professional IT Services"
  5. widget_text: |
  6. No need to worry about amateur service. Get the IT professionals your business needs.
  7. button_text: "Request a Quote"
  8. button_url: "/contact"
56lgkhnf

56lgkhnf1#

页面上的内容看起来不错,但浏览器开发工具不显示任何样式,因为它们根本没有加载。所以这是一个Sass/CSS问题。
大多数样式来自styles_feeling_responsive.scss文件。似乎您错过了导入基础组件中的header-widget.scss文件,因此根本没有加载它。
在再次查看并使用之前的修复(包括丢失的CSS文件)后,我找到了原因。
您的header-widget CSS类必须移动到widget-container内部,因为您的HTML在“小部件”内部定义了“容器”。

  1. <section id="header-widget" class="widget-container">
  2. <div id="sales-widget" class="header-widget">
  3. ...

这是解决办法。请注意,我还将按钮容器移到了小部件容器中。

  1. .widget-container {
  2. background-color: $widget-bg-color;
  3. padding: $widget-padding;
  4. border-radius: 20px;
  5. backdrop-filter: blur(10px);
  6. -webkit-backdrop-filter: blur(10px);
  7. box-shadow: $inner-shadow;
  8. margin-top: 20px;
  9. h1,
  10. h2,
  11. h3,
  12. h4,
  13. h5,
  14. h6 {
  15. font-family: "Libre Baskerville", serif;
  16. color: $header-color;
  17. }
  18. p {
  19. font-family: "Lato", sans-serif;
  20. font-size: 1rem;
  21. color: $txt-color;
  22. }
  23. .header-widget {
  24. position: relative;
  25. max-width: 1000px;
  26. margin-left: auto;
  27. margin-right: auto;
  28. }
  29. .button-container {
  30. position: relative;
  31. button {
  32. border-radius: $global-radius;
  33. }
  34. a {
  35. color: inherit;
  36. text-decoration: none;
  37. }
  38. }
  39. }

结果如下:

展开查看全部

相关问题