Eliminate flash of unstyled content

前端 未结 12 2003
一个人的身影
一个人的身影 2020-11-28 02:39

How do I stop the flash of unstyled content (FOUC) on a web page?

12条回答
  •  -上瘾入骨i
    2020-11-28 03:12

    This is the one that has worked for me and does not require javascript and it works great for pages with many elements and lots of css:

    First, add a dedicated

    Then, at the end of your last .css stylesheet file, set the visibility and opacity styles to 'visible' and '1', respectively:

    html {
        visibility: visible;
        opacity: 1;
    }
    

    If you already have an existing style block for the 'html' tag, then move the entire 'html' style to the end of the last .css file and add the 'visibility' and 'opacity' tags as described above.

    https://gist.github.com/electrotype/7960ddcc44bc4aea07a35603d1c41cb0

提交回复
热议问题