【问题标题】:Pug-Template not importing CSSPug-Template 不导入 CSS
【发布时间】:2019-05-19 04:41:30
【问题描述】:

我正在尝试使用 node.js 创建一个网站并使用 Pug 作为模板语言来表达。 我也在使用 Bootstrap css。

我的问题是 pug 似乎没有导入我自己的 css,而是导入了 Bootstrap css,我不明白为什么。

我尝试使用不同的文件夹/不使用文件夹并将 css 与 pug 文件放在同一个文件夹中,但这也不起作用。

我也试图用一些基本的东西来替换 css 的内容,比如给整个正文或标题块一个背景色,但这也没有用。

任何帮助都会很棒,因为我找不到其他人遇到这个问题。

这是我的哈巴狗文件:

head
  title= title

  //Bootstrap
  link(rel="stylesheet", href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css", integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u", crossorigin="anonymous")
  link(rel="stylesheet", href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css", integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp", crossorigin="anonymous")

  //Jquery
  script(src="https://code.jquery.com/jquery-2.2.4.js", integrity="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI=", crossorigin="anonymous")

  //Own
  link(rel="stylesheet", type="text/css", href="../css/navbar.css")
  script(src="../javascript/navbar.js")

  p  test

  nav
    div(class="menu-icon")
      i(class="fa fa-bars fa-2x")

    div(class="logo")
      LOGO
    div(class="menu")
      ul
        li
          a(href="/") Home
        li
          a(href="/") Home2

还有我的css文件:

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
}

body {
  font-family: "Helvetica Neue",sans-serif;
  font-weight: lighter;
}

header {
  width: 100%;
  height: 100vh;
  background: url(https://wallpaper.wiki/wp-content/uploads/2017/05/wallpaper.wiki-Beautiful-Full-HD-Wallpaper-Download-Free-PIC-WPE0010098.jpg) no-repeat 50% 50%;
  background-size: cover;
}

.content {
  width: 94%;
  margin: 4em auto;
  font-size: 20px;
  line-height: 30px;
  text-align: justify;
}

.logo {
  line-height: 60px;
  position: fixed;
  float: left;
  margin: 16px 46px;
  color: #fff;
  font-weight: bold;
  font-size: 20px;
  letter-spacing: 2px;
}

nav {
  position: fixed;
  width: 100%;
  line-height: 60px;
}

nav ul {
  line-height: 60px;
  list-style: none;
  background: rgba(0, 0, 0, 0);
  overflow: hidden;
  color: #fff;
  padding: 0;
  text-align: right;
  margin: 0;
  padding-right: 40px;
  transition: 1s;
}

nav.black ul {
  background: #000;
}

nav ul li {
  display: inline-block;
  padding: 16px 40px;;
}

nav ul li a {
  text-decoration: none;
  color: #fff;
  font-size: 16px;
}

.menu-icon {
  line-height: 60px;
  width: 100%;
  background: #000;
  text-align: right;
  box-sizing: border-box;
  padding: 15px 24px;
  cursor: pointer;
  color: #fff;
  display: none;
}

@media(max-width: 786px) {

  .logo {
        position: fixed;
        top: 0;
        margin-top: 16px;
  }

  nav ul {
        max-height: 0px;
        background: #000;
  }

  nav.black ul {
        background: #000;
  }

  .showing {
        max-height: 34em;
  }

  nav ul li {
        box-sizing: border-box;
        width: 100%;
        padding: 24px;
        text-align: center;
  }

  .menu-icon {
        display: block;
  }

}

【问题讨论】:

    标签: html css pug


    【解决方案1】:

    找到解决办法,

    我需要添加一行:

    app.use(express.static(__dirname + '/static'));
    

    到我的节点服务器,然后将 css 放入静态文件夹内的文件夹中。

    【讨论】:

      猜你喜欢
      • 2021-08-10
      • 2017-05-31
      • 1970-01-01
      • 1970-01-01
      • 2021-01-06
      • 2019-01-05
      • 2022-10-22
      • 2018-11-23
      • 2021-08-23
      相关资源
      最近更新 更多