跳到正文
WordPress

Style the WordPress “Post Comment” Button with CSS

Target #commentform .form-submit input#submit (or .submit) in Appearance → Customize → Additional CSS or a child theme stylesheet.

测试环境 WordPress 6.x

The default comment button rarely matches a site’s design. You can restyle it with CSS – the safest place is Appearance → Customize → Additional CSS (classic themes), the Site Editor’s custom CSS (block themes), or a child theme stylesheet.

The CSS

Additional CSS
/* Post Comment button */n#commentform .form-submit .submit,n#comments .form-submit input#submit {n    padding: 12px 24px;n    font-size: 16px;n    font-weight: 600;n    background-color: #0369a1;n    color: #ffffff;n    border: none;n    border-radius: 999px;n    cursor: pointer;n    transition: background-color .2s ease, transform .2s ease;n}nn#commentform .form-submit .submit:hover,n#commentform .form-submit .submit:focus-visible {n    background-color: #075985;n    transform: translateY(-1px);n}nn#commentform .form-submit .submit:focus-visible {n    outline: 3px solid #7dd3fc;n    outline-offset: 2px;n}

Adjusting it

PropertyChange it to…
paddingMake the button taller/wider
background-color / colorMatch your brand – keep at least 4.5:1 contrast for accessibility
border-radius0 for square, 6px for slightly rounded, 999px for a pill
:hover rulesThe colour shown when the mouse is over the button

Selector not working?

Some themes use a different ID or class. Right-click the button → Inspect to see its selector, and use that instead. If the theme’s own rules win, make your selector more specific rather than adding !important.

Inder Kochar

作者

Inder Kochar

系统与网络工程师 – 我把为客户使用的解决方案整理成文,并在真实系统上测试过。遇到类似问题了吗?

继续阅读

提出问题或分享您的解决方法

您的邮箱不会公开。评论需经审核——请围绕主题发言。