【问题标题】:How do you set the filepath for css in hiccup with Clojure using the html5 tag?如何使用 html5 标签在 Clojure 中设置 css 的文件路径?
【发布时间】:2014-04-04 01:53:44
【问题描述】:

我正在学习使用 Clojure 进行 Web 开发的基础知识,但似乎无法使用 Hiccup 让我的 css 工作。我已经测试了几个可能的文件路径,尝试使用标签手动设置链接,甚至尝试在 .css 文件的顶部添加 html5, 行。似乎没有任何工作。我确信有一种惯用的方式来做到这一点,我只是不知道。如果有人能告诉我如何一起使用打嗝和 css 以保证它可以工作,我将非常感激。

我的目录有这个树形结构:

.____resources
| |____public
|  |____404.html
|  |____500.html
|  |____home.css <- I want to see this augmenting the html5 in home from the landing.clj, below.
|____src
 |____clojuregrade
  |____landing.clj <- home function with html5 is here.
  |____web.clj

我在上面的landing.clj中有这个功能:

(defn home [& [weights grades error]]
  (html5
    [:head
    [:title ...]
     (include-css "/public/home.css")] ;; <- Is this right?
    [:body
   (form-to [:post "/"]
     (text-area ...)]
     (text-area ...)]
     (submit-button "process"))]))

我在上面的 home.css 中有这段代码:

body {
    background-color: #BAC4E8;
}

h1 {
    font-family: Garamond;
    color: #29507A;

}

注意:我已经删减了上面的代码来尝试概括这个问题,以使其对未来的用户有用。

【问题讨论】:

    标签: css html clojure path hiccup


    【解决方案1】:

    不,您不需要在其前面加上 public/home.csshome.css 就足够了。如果您使用 Compojure,请注意您需要显式公开您的资源(检查:https://stackoverflow.com/a/7820392/206020)。

    【讨论】:

    • 在我的 GET 方法下添加(路由/资源“/”)就可以了!很好的答案。清晰简洁。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2015-04-05
    • 1970-01-01
    • 2020-07-09
    • 1970-01-01
    • 2015-10-17
    • 1970-01-01
    • 2018-07-16
    • 1970-01-01
    相关资源
    最近更新 更多