是否可以在Spring MVC JSP文件中使用Google Fonts?

问题描述 投票:-1回答:2

我已经尝试在JSP文件的头部包含样式表的链接,并尝试在我的项目样式表中使用@import选项。没有任何效果。我也无法找到webjar或任何此类东西。

CSS:

@import url('https://fonts.googleapis.com/css?family=Boogaloo');

body {
    font-family: 'Boogaloo', cursive;
}

JSPF:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="<c:url value="/resources/css/main.css" />" rel="stylesheet">
    <link href="webjars/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Boogaloo" rel="stylesheet">

    <title>HappyLibs Emailer</title>
</head>
java spring jsp spring-mvc google-fonts
2个回答
0
投票

关于使用Google字体,Spring MVC或JSP没有什么特别之处。

根据我的经验,外部文件(如css,javascript和images)通常位于WebContent文件夹(标准版本)或webapp文件夹(maven版本)中。

我不相信c:url标签是必要的。

标准示例:[root] / WebContent / [无论文件夹结构有意义] /main.css

MVN示例:src / main / webapp / [无论文件夹结构有意义] /main.css

我喜欢像 - > / view / page / [特定页面] / [文件]这样的结构

然后,在JSP中:

<!DOCTYPE html >
<html>
     <head>
          ...
          <link href="https://fonts.googleapis.com/css?family=Boogaloo" rel="stylesheet">
          <link href="view/main.css" rel="stylesheet" >
          ...
     </head>
     <body>
          ...
     </body>
</html>

此外,如果浏览器的开发人员工具无法在指定位置找到文件,则应显示错误。

Chrome开发人员工具(即:右键单击页面并选择“检查”):如果控制台选项卡找不到,则会显示错误。 “源”选项卡将显示页面实际加载的文件。 “元素”选项卡将指定应用于相关元素的样式 - >以确保其他内容不会简单地覆盖您期望的样式。


0
投票

发现问题 - 它实际上是由我头脑中的链接顺序引起的。我需要在Bootstrap链接之后应用我的CSS,这样我的样式就不会被覆盖:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="webjars/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Boogaloo" rel="stylesheet">
    <link href="<c:url value="/resources/css/main.css" />" rel="stylesheet" type="text/css">

    <title>HappyLibs Emailer</title>
</head>
© www.soinside.com 2019 - 2024. All rights reserved.