【问题标题】:Semantic UI, loading fonts, 404语义 UI,加载字体,404
【发布时间】:2017-05-03 16:52:49
【问题描述】:

我正在尝试为我的 Phoenix 项目安装 Semantic UI,虽然我可以轻松地让 css 和 javascript 工作,但我无法加载图标。

我已将框架添加到我的供应商文件夹中。

当我加载我的网站时,我在以下路径上得到 404。

GET http://localhost:4000/css/themes/default/assets/fonts/icons.woff2 
GET http://localhost:4000/css/themes/default/assets/fonts/icons.woff 
GET http://localhost:4000/css/themes/default/assets/fonts/icons.ttf 
GET http://localhost:4000/themes/default/assets/fonts/icons.woff2 
GET http://localhost:4000/themes/default/assets/fonts/icons.woff 
GET http://localhost:4000/themes/default/assets/fonts/icons.ttf 

然后我添加了主题文件夹做我的 Plug.Static。

  plug Plug.Static,
    at: "/", from: :myapp, gzip: false,
    only: ~w(css fonts images themes js favicon.ico robots.txt)

但我仍然收到 404,我应该如何配置 Phoenix 以加载包含的字体?

【问题讨论】:

  • 我认为您需要将themes 上移一个目录,直接在static/ 下。这行得通吗?
  • @Dogbert Thx,但我得到了相同的结果:/
  • 我也为此有些挣扎,我已经提取了字体和图像,将它们放在 static/assets 文件夹中以使其正常工作。
  • 我覆盖了我的 css/sass 中的 url。我做了一个答案,让它更清楚。

标签: elixir phoenix-framework


【解决方案1】:

我基本上使用标准语义用户界面,没有任何更改(没有主题...)。

在我的static/vendor 中,我有一个文件夹,其中放置了所有必要的语义 UI 组件 (css/js)。

在static/assets 中,我复制了字体文件夹,并在static/assets/images 文件夹中添加了flags.png 文件。

在文件lib/your_app/endpoint.ex我有:

  plug Plug.Static,
    at: "/", from: :welcome_a, gzip: false,
    only: ~w(css fonts images js favicon.ico robots.txt)

所以字体被提供。

现在是棘手的部分:

在我的 css 中,我覆盖了语义用户界面默认 url 以使事情正常运行:

// Flags sprite URL

i.flag:not(.icon):before 
  background-image: url("/images/flags.png")


// Icons

@font-face 
  font-family: 'Icons'
  src: url("/fonts/icons.eot")
  src: url("/fonts/icons.eot?#iefix") format('embedded-opentype'), url("/fonts/icons.woff2") format('woff2'), url("/fonts/icons.woff") format('woff'), url("/fonts/icons.ttf") format('truetype'), url("/fonts/icons.svg#icons") format('svg')
  font-style: normal
  font-weight: normal
  font-variant: normal
  text-decoration: inherit
  text-transform: none

我认为这不是最好/干净的解决方案,但目前它可以让事情正常进行。希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-11
    • 2017-02-22
    • 2019-02-04
    • 2022-10-07
    • 2014-09-16
    • 2017-08-31
    • 1970-01-01
    • 2018-01-10
    相关资源
    最近更新 更多