Lighthouse audit says content not sized correctly for viewport, despite body width being 100%

杀马特。学长 韩版系。学妹 提交于 2019-12-01 17:10:15

When you reveal the DevTools panel, it usually appears next to the main application page, which messes with the viewport size. I solved the problem by:

  • maximizing the browser window
  • docking the DevTools panel below the page
yacaFx

If you have an "orphan" row Lighthouse fires that error. You need to check where you are using that row and wrap it in a class container-fluid like this:

<div class="container-fluid">
  <div class="row"></div>
</div>

I came across this error when adding my own class to container div that only added some top padding:

<div class="container content">
   <div class="row">
      <div class="col-md-6">
      </div>
   </div>
</div>

Moving my custom class outside made the audit message go away.

<div class="content">
   <div class="container">
      <div class="row">
         <div class="col-md-6">
         </div>
      </div>
   </div>
</div>

add this to your css:

html{overflow-x: hidden;}

I came across this error while working with Nuxt Js (with Bootstrap) project.

It was due to div tags not closed properly. Normally, you encounter this error when the div hierarchy is not properly maintained, even if you have properly declared viewport meta tag.

For example:

<div class="container-fluid">
  <div class="row">
    <div class="col-md-6">

    </div>
  </div>
</div>

Now, if you declare class "row" without defining "container" or "container-fluid", the site content doesn't render with proper margins & paddings needed to fit the content on mobile device; which is the reason why this audit fails on Google Lighthouse.

Let me know, if this resolves your issue.

Before running the audit test, set the zoom of the browser to 100%. At 100% zoom I passed the audit. For smaller or greater that 100% zoom I got the "Content is not sized correctly for viewport" message - for the desktop audit. Mobile audit was always ok.

This setting is affected by the chrome in some browsers. Notably, Vivaldi's "Panel" on the left side (by default) alters the measurement Lighthouse is using to compare window.innerWidth === window.outerWidth. You'll need to turn this off to make it work.

To turn this off in Vivaldi, click the main Vivaldi menu in the upper left corner, select "View", then "Show Panel" to toggle it. Alternatively, hit the F4 key.

Rerun your Lighthouse audit, expand the "Passed Audits" and you should see "Content is size correctly for the viewport".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!