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

Fix the WordPress 2025 Theme Calendar Not Filling the Sidebar Width

图3:应用修正后的 CSS,日历占据了应有的侧边栏宽度,有文章的日子用主题同色系进行了高亮,悬停时会变黑

1. Troubleshooting: Not a Narrow Sidebar, but Automatic Column Shrinkage

Figure 1: Initial state. My sidebar isn't actually narrow, but the calendar only takes up a little over half the space in the middle
Figure 1: Initial state. My sidebar isn’t actually narrow, but the calendar only takes up a little over half the space in the middle

When I first looked at this sidebar calendar, it always felt out of place and looked very “cramped.” But my sidebar isn’t actually narrow, so what was the problem?
By examining the underlying HTML structure, I found the root cause: the default WordPress calendar table uses adaptive column widths (table-layout: auto). Because the date in each cell is just a single digit like “1, 2, 3,” the browser assumes the cells don’t need to be very wide and aggressively compresses the column widths to the minimum. As a result, the calendar takes up less than 2/3 of the sidebar width, leaving large blank areas on both sides.

2. Style Tracing: Locating the Core Element

Figure 2: Searching for .wp-block-calendar th in the browser developer tools, found the Gutenberg system default styles
Figure 2: Searching for .wp-block-calendar th in the browser developer tools, found the Gutenberg system default style file

The default system settings are very basic, with only a minimal padding of .25em. To completely overhaul this, the standard block panel adjustments were no longer effective, so I decided to directly enforce a global override in WordPress Dashboard → Design → Styles → Additional CSS.

3. Implementation: Core CSS Code (with Modification Notes)

I wrote the following CSS with the core objectives of:

  1. Force equal column widths: Use table-layout: fixed to evenly distribute the sidebar width across the 7 days.
  2. Enlarge font size and padding: Make the calendar look more spacious.
  3. Highlight days with posts: Remove the default underline, apply the theme color, and add a hover effect.

⚠️ Key Note:
The color #503aa8 used in the code is actually a fairly dark blue-purple (indigo). If you feel it leans too blue, you can change it to whatever color you need at any time.

Here is the final, complete, and modified CSS code (just copy and paste it into “Additional CSS”):

CSS
/* ==========================================================================
   🔥 侧边栏日历放大优化 (包含横撑满修复)
   解决:默认日历字体偏小、列宽没撑满侧边栏的问题。
   ========================================================================== */

/* 1. 放大月份标题 ("2026年 6月") */
.wp-block-calendar caption {
    font-size: 1.3em !important;
    font-weight: bold !important;
    margin-bottom: 12px !important;
    text-align: center !important;
}

/* 2. 放大日期格子 (单元格内边距和字体) */
.wp-block-calendar td,
.wp-block-calendar th {
    font-size: 17px !important;  /* 日期数字放大 */
    padding: 12px 8px !important; /* 格子上下左右拉开,变舒展 */
    text-align: center !important;
}

/* 3. 保证表格宽度占满侧边栏 (配合强制列宽平分) */
.wp-block-calendar table {
    width: 100% !important;
    table-layout: fixed !important; /* 👈 关键:强制星期一至星期日 7 列等宽平分,彻底撑满! */
    border-collapse: collapse !important;
}

/* 4. 消除日历外层左右内边距,让表格彻底贴紧侧边栏左右边缘 */
.wp-block-calendar {
    padding-left: 0 !important;
    padding-right: 0 !important;
}

/* 5. 放大底部导航 ("« 5月") */
.wp-calendar-nav {
    margin-top: 15px !important;
    font-size: 16px !important;
    display: flex !important;
    justify-content: space-between !important;
}
.wp-calendar-nav a {
    text-decoration: none !important;
    color: inherit !important;
}

/* 6. 换成主题自定义颜色、加粗 */
.wp-block-calendar td a {
    color: #503aa8 !important;        /* 👈 主题紫蓝色,觉得偏蓝可以改为纯黑 #000000 或亮红 #d63638 */
    font-weight: 700 !important;      /* 👈 加粗字体 */
    padding-bottom: 2px !important;
    transition: all 0.2s ease !important;
}

/* 7. 当鼠标放上去的时候,颜色变成全黑 */
.wp-block-calendar td a:hover {
    color: #000000 !important;
    border-bottom-color: #000000 !important;
}

4. Final Result Showcase

Figure 3: With the modified CSS applied, the calendar occupies its proper sidebar width, days with posts are highlighted using the theme's color scheme, and they turn black on hover

After applying the above code, the “cramped” calendar that was previously shrunk in the middle instantly transformed. Not only does the table now stretch across the entire sidebar, but it also immediately looks more spacious and elegant visually, significantly improving the reading experience.

系列导航

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

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

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

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

关于我  ·  GitHub  ·  邮件联系