简体   繁体   English

使用方尖碑时css文件放在哪里

[英]Where to put the css file when using obelisk

I want to make two div's float side by side using Obelisk.我想使用方尖碑并排浮动两个 div。 For this I used the information from this post, How to place div side by side and for this solution classes have to be declared in css.为此,我使用了这篇文章中的信息, 如何并排放置 div并且为此解决方案类必须在 css 中声明。 Following the advice of this tutorial ( https://github.com/hansroland/reflex-dom-inbits/blob/master/tutorial.md ), more specifically the part about mainWidgetWithHead, I put the commands in a different file.按照本教程( https://github.com/hansroland/reflex-dom-inbits/blob/master/tutorial.md )的建议,更具体地说是关于 mainWidgetWithHead 的部分,我将命令放在不同的文件中。 The problem is, however, that I can't find where the css-file should be stored in order to get accessed by the program.但是,问题是我找不到 css 文件应该存储在哪里才能被程序访问。

I tried to put it in several places within the automatically generated directory by "ob init", but I always end up with an empty css-file when I load it in my browser.我试图将它放在通过“ob init”自动生成的目录中的几个地方,但是当我在浏览器中加载它时,我总是以一个空的 css 文件结束。

Below you can see a minimal example of the frontend function used in frontend/src/Frontend.hs.您可以在下面看到 frontend/src/Frontend.hs 中使用的前端函数的最小示例。

frontend :: Frontend (R FrontendRoute)
frontend = Frontend
    { _frontend_head = prerender_ (text "Loading..") headElement
    , _frontend_body = prerender_ (text "Loading...") bodyElement
    }

headElement :: MonadWidget t m => m ()
headElement = do
    el "title" $ text "Title"
    styleSheet "/css/cssTest.css"
        where
            styleSheet link = elAttr "link" (Map.fromList [
                    ("rel", "stylesheet"),
                    ("type", "text/css"),
                    ("href", link)
                ]) $ return ()

bodyElement :: MonadWidget t m => m ()
bodyElement = elClass "div" "container" $ do
    elClass "div" "fixed" $ do
        el "h2" $ text "Button enabled / disabled"
    elClass "div" "flex-item" $ do
        el "h2" $ text "Second paragraph next to it."

This error message is consequently given, no matter where I put the css-file: Resource interpreted as Stylesheet but transferred with MIME type text/plain: " http://127.0.0.1:8000/css/cssTest.css "此错误消息给出因此,无论身在何处,我把CSS文件:资源解释为样式表,但使用MIME类型text / plain的转移:“ http://127.0.0.1:8000/css/cssTest.css

You should store all of the static assets your site needs live in the static directory created by ob init .您应该将站点需要的所有静态资产存储在ob init创建的static目录中。 this is especially important for mobile builds.这对于移动构建尤其重要。

The other thing you need to do is refer to those assets like the following:您需要做的另一件事是参考这些资产,如下所示:

styleSheet $ static @"css/cssTest.css"
             ^^^^^^^^

assuming you've turned on TypeApplications , which is the default in the obelisk skeleton.假设您已打开TypeApplications ,这是方尖碑骨架中的默认设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM