【问题标题】:How to add an image to be used in the customized css file - Swagger UI - Swashbuckle如何添加要在自定义 css 文件中使用的图像 - Swagger UI - Swashbuckle
【发布时间】:2015-09-20 22:40:32
【问题描述】:

我使用 Swagger(Swashbuckle) 作为我们 Web API 项目的文档工具。我可以使用自定义的 css 文件自定义 index.html。 一切都很好,除了,我想在索引页面中添加我们公司的特定徽标,我无法让它工作。

建议??

【问题讨论】:

    标签: swagger swagger-ui swashbuckle


    【解决方案1】:

    我意识到这是一个较老的问题,但我今天才遇到这个问题。如果要嵌入图像文件,可以类似于对 css 和索引文件的操作。

    在 SwaggerConfig 中添加一行,如下所示:

    c.CustomAsset("mylogo", thisAssembly, "YourWebApiProject.SwaggerExtensions.mylogo.png");
    

    然后,您可以在修改后的 css 或自定义索引页面中引用该文件,方法是在修改后的 html 中使用 <img src="mylogo" /> 或在自定义 css 文件中使用 url(../mylogo) 作为路径。

    与您的 index 和 css 文件类似,请确保将其设置为嵌入式资源。

    【讨论】:

      【解决方案2】:

      在你的 CSS 中包含这个怎么样:

      .swagger-section #header a#logo {
        background-image: url(path/to/my/logo);
      }
      

      【讨论】:

        猜你喜欢
        • 2018-06-17
        • 1970-01-01
        • 2021-03-01
        • 1970-01-01
        • 2018-10-04
        • 2022-08-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多