没有不值得去解决的问题,也没有不值得去学习的技术!

Horizontal Scrollbars on WordPress Pages: A Complete Troubleshooting Log From CSS to the Block Editor

页面底部出现横向滚动条。

Recently, while updating my blog’s “About Me & Contact” page, I noticed a horizontal scrollbar suddenly appearing at the bottom of the page.

At first, I thought it was a CSS issue, but I eventually discovered that the real cause was the “Full Width” setting in a Gutenberg block.

This article documents the complete troubleshooting process, so I can quickly locate the issue if I encounter similar problems in the future.


Symptom

Page:

Plaintext
https://www.shuijingwanwq.com/about-me-contact/

A horizontal scrollbar appeared at the bottom of the desktop browser.

A horizontal scrollbar appears at the bottom of the page.
A horizontal scrollbar appears at the bottom of the page.

The page content itself did not contain any unusually wide images or tables, so my initial reaction was confusion.


Step 1: Identify what is stretching the page

First, I opened the browser developer tools (F12).

I executed the following in the Console:

JavaScript
[...document.querySelectorAll('*')]
.filter(el => el.scrollWidth > document.documentElement.clientWidth)
.map(el => ({
    tag: el.tagName,
    class: el.className,
    id: el.id,
    width: el.scrollWidth
}))

The output looked like this:

Plaintext
HTML
BODY
wp-site-blocks
MAIN
entry-content alignfull

The most important line here is:

Plaintext
entry-content alignfull

This indicated that the entire content area was exceeding the viewport width, rather than a specific image or div.


Step 2: Suspect CSS

Initially, I suspected:

  • An image was too wide
  • iframe
  • table
  • pre
  • A plugin was outputting a fixed width

I was even about to just write:

CSS
body{
    overflow-x:hidden;
}

But that would only hide the problem, not actually fix it.

Therefore, I did not proceed with modifying the CSS.


Step 3: Check the page editor

Since the problem occurred at:

Plaintext
entry-content alignfull

It likely originated from Gutenberg.

I opened the page editor.

I checked the outermost Group block.

I found:

Plaintext
Alignment:

Full Width

So, I tried changing it to:

Plaintext
Wide Width

Saved.

Refreshed the page.

The horizontal scrollbar disappeared immediately.

After changing the Group alignment from "Full Width" to "Wide Width", the issue was resolved immediately.

Root cause

The actual problem was not the CSS.

It was:

Plaintext
Group

Alignment

Full Width

After changing it to:

Plaintext
Wide Width

It returned to normal.

This indicates that the current theme (Twenty Twenty-Five) and my website’s current layout have a compatibility issue with the calculation of Full Width on certain pages.


Why could the console locate it?

Because the executed JS finds:

Plaintext
scrollWidth > viewport

That is:

Which elements have an actual width exceeding the browser’s viewport width.

If the output is:

Plaintext
img

It means an image is too wide.

If the output is:

Plaintext
table

It means a table is too wide.

If the output is:

Plaintext
pre

It means a code block is too wide.

This time, the output was:

Plaintext
entry-content alignfull

So I quickly locked onto the entire content container.


My summarized troubleshooting process

If I encounter a horizontal scrollbar on a WordPress page in the future, I plan to consistently follow this troubleshooting order.

Step 1

Console:

JavaScript
[...document.querySelectorAll('*')]
.filter(el => el.scrollWidth > document.documentElement.clientWidth)

Find the element that is actually too wide.


Step 2

If it is:

Plaintext
img
table
iframe
pre

Check the corresponding content directly.


Step 3

If it is:

Plaintext
entry-content

wp-block-group

alignfull

Check first if the following are set to:

Plaintext
Group

Columns

Cover

Gallery

Whether they are set to:

Plaintext
Full Width

If not necessary, change to:

Plaintext
Wide Width

Then retest.


Step 4

Only consider modifying the CSS as a last resort.

Do not start by applying:

Plaintext
overflow-x:hidden;

Otherwise, you are just masking the problem instead of actually fixing it.


Takeaway

The biggest takeaway this time was not just fixing the horizontal scrollbar.

It was forming a repeatable troubleshooting process for the future:

First, use the browser developer tools to locate the overflowing element, then return to the WordPress block editor to check the corresponding block, and only consider CSS fixes last.

Compared to directly modifying styles, this method locates the issue faster and makes it easier to find the root cause.

系列导航

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系