How do ASP.NET Core's “asp-fallback-*” CDN tag helpers work?

前端 未结 2 1678
南旧
南旧 2020-12-15 18:51

I understand what the asp-fallback-* tag helpers do. What I don\'t understand is how.

For example:



        
2条回答
  •  盖世英雄少女心
    2020-12-15 19:19

    TL;DR:

    • A tag is added to the DOM that has a CSS class of sr-only.
    • Additional JavaScript is written to the DOM, which:
      1. Locates said element.
      2. Checks whether said element has a CSS property position that is set to absolute.
      3. If no such property value is set, an additional element is written to the DOM with a href of ~/lib/bootstrap/dist/css/bootstrap.min.css.

    The LinkTagHelper class that runs against your elements inserts a element in the output HTML that is given a CSS class of sr-only. The element ends up looking like this:

    
    

    The code that generates the element looks like this (source):

    builder
        .AppendHtml("");
    

    Unsurprisingly, the value for FallbackTestClass is obtained from the 's asp-fallback-test-class attribute.

    Right after this element is inserted, a corresponding

提交回复
热议问题