最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

css - Why is there excessive spacing between elements in ReactMarkdown rendering? - Stack Overflow

programmeradmin5浏览0评论

I'm using Next.js 15 with Tailwind CSS V3 and the react-markdown package to render AI chat output inside a component.

I've customized the markdown rendering to replace all <h1>, <h2>, <h3> elements with styled <div>s using Tailwind classes to avoid default typography spacing issues.

Despite this, there’s still excessive vertical space between elements — particularly under h1, h2, and h3 replacements. I've tried removing all margin-bottom and adding mb-0, mt-0, etc., but spacing persists.

Here’s what it looks like (I’ve added debug background colors and annotations):


✅ What I’m using:

  • Next.js 15
  • React 19
  • ReactMarkdown react-markdown@9
  • Tailwind CSS v3
  • Plugins:
    • remark-gfm
    • rehype-highlight

✅ Expected result:

Minimal vertical spacing between elements in the chat bubbles.

❌ Actual result:

Headings and their following content have unwanted gaps that don’t collapse.


发布评论

评论列表(0)

  1. 暂无评论