如何给标题栏添加图标

How to add icon to title bar

我正在尝试制作 Web 应用程序,我需要在我的标题栏中添加一个带有名称的图标。

我正在使用包含 Web 表单的 MVC 中的空项目制作 Web 应用程序。我正在使用 Visual studio 2017 进行编码。到目前为止,我已经尝试了如下布局。

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<link href="~/Content/nav.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="icon" type="image/svg" href="~/Content/img/download.png" />
<script src="~/Scripts/layout.js"></script>
<title>@ViewBag.Title</title>
</head>

<body>
<navbar>
    <div class="topnav" id="myTopnav">
        <a href="Home/Index">Home</a>
        <a href="Login/login">Login</a>
        <a href="Payment/Payment"> Payment </a>
        <a href="Register/register">Customer Registration</a>
        <a href="javascript:void(0);" class="icon" onclick="myfunction()">
            <i class="fa fa-bars"></i>
        </a>
    </div>
    <div>
        @RenderBody()
    </div>
</navbar>  
</body>
</html>

我试过link标题前的图片,但转错了。由于我是MVC的新手,请给我一些在标题栏中添加图标的方法。

您要查找的内容称为 favicon。您可以从 png 或其他任何格式生成它,然后像这样将其包含在您的页面中:

<link rel="icon" href="/favicon.ico" type="image/x-icon">

这是一个网站图标生成器(其中之一): https://www.favicon-generator.org/

问题出在这段代码中:

<link rel="icon" type="image/svg" href="~/Content/img/download.png" />

您指定的类型是 image/svg 而不是 image/png.

确保 Content/img 文件夹中存在 png 图片。