【问题标题】:Why is my website deploy not working with CSS?为什么我的网站部署无法使用 CSS?
【发布时间】:2022-01-25 07:31:29
【问题描述】:

我尝试在 netlify 上部署我的网站目录,所有“HTML”似乎都可以正常工作,但没有显示任何“CSS”。它似乎确实作为本地主机工作。有谁知道怎么回事。

4:54:44 PM: Creating deploy upload records
4:54:45 PM: Starting post processing
4:54:45 PM: Post processing - HTML
4:54:45 PM: Post processing - header rules
4:54:45 PM: Post processing - redirect rules
4:54:45 PM: Post processing done
4:54:45 PM: Site is live ✨

【问题讨论】:

  • 您是否尝试清除缓存?
  • 可以把网站的链接发过来吗?或者你网站的html
  • @LaaouatniAnas mohammadalafshate.ca
  • @Tagi 请问这是怎么工作的?
  • 您的 css 文件未加载或未找到。确保这是正确的路径。 <link rel="stylesheet" type="text/css" href="../NEWW/css/style.css">.

标签: html css netlify


【解决方案1】:

我去了你链接到我的网站, 然后我打开了 Firefox dev-tools

我注意到 CSS 的链接似乎是正确的

Firefox 的dev-tools 有一个函数叫 STYLE EDITOR

我注意到 CSS 文件已部署,

但是你把 HTML 和 CSS 搞混了,事实上,你在 CSS 里面写了 HTML ...

一定要删除 HTML 标签(那些在 style.css 文件中的)

这是我如何做到的视频https://imgur.com/a/6gqvxOd

之前

之后


编辑后 (style.css)

    body {
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
      background: rgb(14, 30, 37);
      color: white;
      overflow: hidden;
      margin: 0;
      padding: 0;
    }

    h1 {
      margin: 0;
      font-size: 22px;
      line-height: 24px;
    }

    .main {
      position: relative;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      height: 100vh;
      width: 100vw;
    }

    .card {
      position: relative;
      display: flex;
      flex-direction: column;
      width: 75%;
      max-width: 364px;
      padding: 24px;
      background: white;
      color: rgb(14, 30, 37);
      border-radius: 8px;
      box-shadow: 0 2px 4px 0 rgba(14, 30, 37, .16);
    }

    a {
      margin: 0;
      text-decoration: none;
      font-weight: 600;
      line-height: 24px;
      color: #007067;
    }

    a svg {
      position: relative;
      top: 2px;
    }

    a:hover,
    a:focus {
      text-decoration: underline;
      text-decoration-color: #f4bb00;
    }

    a:hover svg path{
      fill: #007067;
    }

    p:last-of-type {
      margin-bottom: 0;
    }

之前(style.css)

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

    <title>Page Not Found</title>
    <link href='https://fonts.googleapis.com/css?family=Roboto:400,700&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
    <style>
    body {
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
      background: rgb(14, 30, 37);
      color: white;
      overflow: hidden;
      margin: 0;
      padding: 0;
    }

    h1 {
      margin: 0;
      font-size: 22px;
      line-height: 24px;
    }

    .main {
      position: relative;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      height: 100vh;
      width: 100vw;
    }

    .card {
      position: relative;
      display: flex;
      flex-direction: column;
      width: 75%;
      max-width: 364px;
      padding: 24px;
      background: white;
      color: rgb(14, 30, 37);
      border-radius: 8px;
      box-shadow: 0 2px 4px 0 rgba(14, 30, 37, .16);
    }

    a {
      margin: 0;
      text-decoration: none;
      font-weight: 600;
      line-height: 24px;
      color: #007067;
    }

    a svg {
      position: relative;
      top: 2px;
    }

    a:hover,
    a:focus {
      text-decoration: underline;
      text-decoration-color: #f4bb00;
    }

    a:hover svg path{
      fill: #007067;
    }

    p:last-of-type {
      margin-bottom: 0;
    }

    </style>
  </head>
  <body>
    <div class="main">
      <div class="card">
        <div class="header">
          <h1>Page Not Found</h1>
        </div>
        <div class="body">
          <p>Looks like you've followed a broken link or entered a URL that doesn't exist on this site.</p>
          <p>
            <a id="back-link" href="/">
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
                <path fill="#007067" d="M11.9998836,4.09370803 L8.55809517,7.43294953 C8.23531459,7.74611298 8.23531459,8.25388736 8.55809517,8.56693769 L12,11.9062921 L9.84187871,14 L4.24208544,8.56693751 C3.91930485,8.25388719 3.91930485,7.74611281 4.24208544,7.43294936 L9.84199531,2 L11.9998836,4.09370803 Z"/>
              </svg>
              Back to our site
             </a>
          </p>
          <hr><p>If this is your site, and you weren't expecting a 404 for this path, please visit Netlify's <a href="https://answers.netlify.com/t/support-guide-i-ve-deployed-my-site-but-i-still-see-page-not-found/125?utm_source=404page&utm_campaign=community_tracking">"page not found" support guide</a> for troubleshooting tips.
          </p>
        </div>
      </div>
    </div>
    <script>
      (function() {
        if (document.referrer && document.location.host && document.referrer.match(new RegExp("^https?://" + document.location.host))) {
          document.getElementById("back-link").setAttribute("href", document.referrer);
        }
      })();
    </script>
  </body>
</html>

【讨论】:

  • 如果这对你有帮助,我会很高兴:)
  • 这很有帮助,我希望我可以投票,但我只有 11 个声望,所以他们不允许我 :( 但还是谢谢!
  • 谢谢你,当你有足够的声誉时,记得点赞,让其他人知道它对你有帮助并且答案是正确的。
【解决方案2】:

我看到 CSS 链接已损坏?我建议使用“../css/style.css”,或者如果您计划更大的项目将 css 文件夹与更多文件夹(如 /main、/buttons 等)分离,则可以更好地分离。

【讨论】:

    【解决方案3】:

    奇怪的是,我发现在 PyCharm 上编码时,我必须使用目录“../NEWW/css/style.css”,否则如果我运行本地主机,CSS 文件将无法工作。但是在部署或发布时,我必须使用不带“/NEWW”的目录“../css/style.css”才能使 CSS 文件生效。

    【讨论】:

    • 现在一切都居中了,你不用再用 CSS 编写 HTML 了……干得好!
    猜你喜欢
    • 2022-07-22
    • 1970-01-01
    • 2023-01-16
    • 1970-01-01
    • 2018-09-27
    • 2015-09-28
    • 2015-10-23
    • 1970-01-01
    • 2018-12-25
    相关资源
    最近更新 更多