【问题标题】:Some Font Awesome icons show, some do not [duplicate]一些字体真棒图标显示,一些不显示[重复]
【发布时间】:2019-01-14 20:16:43
【问题描述】:

我正在使用 ExpressJS 通过 POST 和 AJAX 访问 OpenWeather API,只是为了比较这两种方法。

在所有事情中(所有 JS 工作),我遇到了字体真棒问题。有些显示,有些不显示。

我已经尝试了将 i 标签单独放置在所有各种元素中的所有方法。结果不一致。

无论如何这里是标记:

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous"> // this is the FA link

<input id="getIt" name="cityajax" type="text" class="ghost-input" placeholder="Enter a City" required>
<button id="submit">Submit</button>
     <div class="textAlignCenter">
         <img src="https://upload.wikimedia.org/wikipedia/commons/b/b1/Loading_icon.gif" />
     </div>
     <div id="message"></div><span id="displaySky"> </span> // the icon here shows, but only after the class is added via jQuery

     <div class="wrapper">
       <div>
         <span class="humidLogo"></span> <i class="far fa-humidity" ></i> Current humidity:   <span class="apiHumidity"> % </span> // this icon does not show

     </div>

     <div>
       <span class="windLogo"></span> <i class="fas fa-windsock"></i>  Wind speed is:   <span class="apiWind"> km/h </span> //this icon does not show either

   </div>
     </div>

相关的CSS在这里,请不要乱说,这是我试过的:-)

    .fa {
            color:violet;

        }
        .fas, .far {
            color:violet;

        }
        #displaySky {
          display: block;
          width:100%;
          margin: 20px auto;
          margin-bottom: 35px;
          text-align: center;
          color:violet;
          font-size:1.3em;
        }

        #message {
          display: block;
          width:100%;
          margin: 20px auto;
          text-align: center;
          color:black;
        }


        i {
          color: violet; font-size:2em !important;
        }
        .wrapper {
          margin:10px;
          border: grey 1px solid;
          padding: 30px;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: column;
-webkit-flex-wrap: nowrap;
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
justify-content: space-between;
-webkit-align-content: space-between;
-ms-flex-line-pack: justify;
align-content: space-between;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
        }

还有 JS,这应该不会有任何影响,但有趣的是我添加图标类的那一行,该图标确实出现了,只需通过在输入字段中输入城市来运行 ajax 请求,您将看,徽标已正确添加。

如果这个 JS 可以优化一点,我会接受一些反馈,我尝试通过 EJS 根据天气显示不同的图标,但这太混乱了,变量没有跨文件范围,我simple 更喜欢 jQuery 的方式。

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}  // ignore this


    $("#submit").click(function (e) {

var 目的地 = ($("#getIt").val());

            $.post("http://api.openweathermap.org/data/2.5/weather?q=" +
            destination +
            "&units=metric&appid=15c9456e587b8b790a9092494bdec5ff",
            function (result, status, xhr) {

                var APIresponded =  result["main"]["temp"];
                var APIweather =  result["weather"][0]["description"];
                var sunGoing = result["sys"]["sunset"];
                var output = destination.capitalize();
                var humidValue = result["main"]["humidity"];
                var windy = result["wind"]["speed"];
                if (APIweather.includes("snow")) {
                  $('#displaySky').addClass('far fa-snowflake');
                }
                if (APIweather.includes("rain")) {
                  $('#displaySky').addClass('fas fa-cloud-rain');
                }
                if (APIweather.includes("overcast")) {
                  $('#displaySky').addClass('fas fa-smog');
                }
                if (APIweather.includes("sun") || APIweather.includes("clear")) {
                  $('#displaySky').addClass('fas fa-sun');
                }
                if (APIweather.includes("scattered")) {
                  $('#displaySky').addClass('fas fa-cloud-sun'); // All these if clauses work and add the icons
                }
                $("#message").html("The temperature in " + output + " is : " + APIresponded + " degrees. The sky looks like this: ");
                $(".apiHumidity").text(humidValue + " %");
                $('.humidLogo').addClass('fas fa-humidity'); // not working
                $('.apiWind').html(windy + 'km per hour');
                console.log(APIweather);
            }

            ).fail(function (xhr, status, error) {
                alert("Result: " + status + " " + error + " " +
                xhr.status + " " + xhr.statusText);
            });
        });


    $(document).ajaxStart(function () {
        $("img").show(300);
    });

    $(document).ajaxStop(function () {
        $("img").hide(300);
    });

就是这样,我已经创建了一个codepen:

https://codepen.io/damPop/pen/qLgRvp?editors=1000

那么,为什么图标不显示?当我检查开发工具时,它们确实出现在 DOM 中,但大小为 0/0px。尝试添加 !important 规则,也没有用。 我错过了什么?我已经阅读了关于 SO 的类似主题,但没有一个对此有帮助。我也不认为这是一个 flexbox 问题。

【问题讨论】:

    标签: jquery html css font-awesome-5


    【解决方案1】:

    这些特定图标,fa-humidityfa-windsock,仅适用于 Font Awesome Pro 许可证。要解决此问题,您需要获得许可证,然后download Pro 相关文件。

    【讨论】:

    • 另外,如果您拥有 PRO 许可证,请确保您在其页面的设置中允许您的域。
    • 大声笑,这花了我几个小时的“调试”时间。我如何知道哪些已获得许可?我可以不只是简单地使用源代码,因为它们都使用内容属性吗?哦,那我怎么知道哪些没有授权?
    • @ptts 您需要检查该站点并找到此信息。阅读重复链接,您将获得更多详细信息。还有你需要考虑的版本
    • 搜索时在左侧边栏上方,点击“免费”;这将向您显示哪些可用于免费许可证
    猜你喜欢
    • 1970-01-01
    • 2018-02-16
    • 1970-01-01
    • 2017-04-20
    相关资源
    最近更新 更多