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

Optimize WordPress Popular Posts Spacing to Improve Reading Experience

图 2:区块右侧面板的“额外 CSS”输入框。

While maintaining my blog recently, I noticed that the spacing between list items in the sidebar’s “Most Viewed Posts” widget was too small. The text was crammed together, which not only looked unappealing but also made it difficult for readers to scan quickly. After some trial and error, I managed to solve this problem perfectly using custom CSS. This article documents the exact steps I took and provides the ready-to-use code, hoping to help others facing the same issue.


Current Problem: Default Spacing Is Too Tight

As shown in the image below, the list items are packed tightly together with no visual breathing room. This becomes especially cramped when longer titles wrap to the next line:

Figure 1: Default styling of the Most Viewed Posts list. The spacing is too tight, reducing reading comfort.
Figure 1: Default styling of the Most Viewed Posts list. The spacing is too tight, reducing reading comfort.

⚠️ Pitfall Reminder: The Block’s Built-in “Additional CSS” Is a Trap

Many people (myself included) would immediately think of finding the “Additional CSS” input box in the block editor’s “Advanced” settings (see image below), confidently paste the full selector code into it, only to find that nothing changes.

Figure 2: The "Additional CSS" input box in the block's right-hand panel.
Figure 2: The “Additional CSS” input box in the block’s right-hand panel.

If you look closely below this input box, there is actually a line of small gray text that explains:

“Add your own CSS to customize the appearance of the Most Viewed Posts block. You do not need to include a CSS selector, just add the property and value, e.g. color: red;.”

Translated, this means: You do not need to write a selector, only the property and value, for example, color: red;.

This implies:

  • This input box only accepts pure CSS declarations (like margin-bottom: 20px;),
  • The styles are applied to the block’s outermost container (<div>),
  • It cannot reach the internal <li> elements to adjust the list item spacing.

I completely missed this prompt at first. I repeatedly pasted the full .wp-block-post-views-counter-most-viewed-posts ol li { ... } and saw no effect, wasting a lot of time troubleshooting caching issues and theme conflicts. It wasn’t until I stumbled upon that explanation that it dawned on me—I was taking the wrong approach.

Therefore, the block’s built-in “Additional CSS” does not suit our needs; we must use a different method.


✅ Correct Solution: Use the Site Editor’s (FSE) Global “Additional CSS”

If you are using a WordPress block theme (i.e., a Full Site Editing theme), add custom CSS via the following path:

Steps

  1. Go to your WordPress dashboard, click Appearance → Editor in the left menu to open the Site Editor.
    (If your theme does not have an “Editor” option, it is not a block theme. You can still use the Additional CSS under “Appearance → Customize”, but this article focuses on the block theme environment.)
  2. At the top of the Site Editor, click the “Styles” icon (usually a circular palette or pencil icon). The Styles panel will pop out on the right.
  3. In the Styles panel, scroll down to find the “Additional CSS” section (as shown below).
  4. Paste the CSS code we prepared completely into the text box, then click “Save” to publish.
  5. Clear your site cache (plugin cache, CDN, etc.) and refresh the front-end page to see the effect.
Figure 4: Adding global Additional CSS in the Site Editor's Styles panel.
Figure 4: Adding global Additional CSS in the Site Editor’s Styles panel.

📝 CSS Code Breakdown

I used clearly commented code to make future adjustments easier. The core logic is:

  • Add a bottom margin to each list item (margin-bottom) to increase the vertical spacing;
  • Add a light divider line (border-bottom) to make the hierarchy of items clearer;
  • Remove the extra margin and divider line from the last item to keep it clean;
  • Fine-tune the styling of the counter numbers to make them look more harmonious.
CSS
/* ==========================================================================
   🔥 热门文章列表间距优化
   解决:增加列表项之间的垂直间距,添加分割线提升可读性,优化计数样式。
   ========================================================================== */

/* 热门文章列表项间距优化(适用于整个网站) */
.wp-block-post-views-counter-most-viewed-posts ol li {
    margin-bottom: 20px;          /* 列表项之间的垂直间距,可按需加大(如 24px) */
    padding-bottom: 6px;          /* 内部下内边距,增加呼吸感(可选) */
    border-bottom: 1px solid #e5e5e5; /* 浅色分割线,让层次更清晰(可选) */
}

/* 最后一项去掉底部边距和分割线,保持整洁 */
.wp-block-post-views-counter-most-viewed-posts ol li:last-child {
    margin-bottom: 0;
    border-bottom: none;
}

/* 让计数数字与标题更和谐(可选) */
.wp-block-post-views-counter-most-viewed-posts ol li .count {
    margin-left: 8px;
    font-size: 0.85em;
    color: #999;
}

🎯 Final Result: Comfortable Spacing and Clear Hierarchy

After applying the styles above, the Most Viewed Posts list became well-spaced. There is a clear gap between each entry, and the divider lines further guide the eye, significantly improving the overall browsing experience:

Figure 5: The optimized list. The spacing is noticeably larger, and the divider lines make the items clear at a glance.
Figure 5: The optimized list. The spacing is noticeably larger, and the divider lines make the items clear at a glance.

Comparing the screenshots before and after the adjustment (Figure 1 and Figure 5), the effect is immediate. If you feel that a 20px spacing is still not large enough, simply change the value of margin-bottom, for example to 28px or 32px.


💡 Notes

  • If your theme’s built-in styles have a higher priority, you can append !important to the property value to force an override (e.g., margin-bottom: 20px !important;).
  • Be sure to clear your site cache (plugin cache, CDN cache, etc.) and refresh your browser to ensure you see the updates.
  • This selector only targets the specific wp-block-post-views-counter-most-viewed-posts block and will not affect other lists, so you can use it with confidence.
  • If your theme is not a block theme (lacks the “Editor” menu), please use the Additional CSS under “Appearance → Customize” instead; it works just as well.

I hope this blog post helps you. If you encounter any issues during the process, feel free to leave a comment!

系列导航

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

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

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

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

关于我  ·  GitHub  ·  邮件联系