question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CodeMirror-sizer gets unnecessary negative margin-bottom

See original GitHub issue

I recently updated an app from CodeMirror 4.7.1 to 4.8.1 and https://github.com/codemirror/CodeMirror/commit/b8ea5a73c1410d41c7c51a8dab3bfb2ce11cb669 has been causing some trouble. I’m still trying to figure out a compact repro case, but essentially we have a CodeMirror in styled like

.CodeMirror {
  position: absolute;
  width: 100%;
  height: 100%;
}

The commit above has made it so that CodeMirror-scroller has a negative margin-bottom, which makes it so that when one scrolls down to the bottom of the document, the last line is partially cut off. A temporary fix is to have a rule with margin-bottom: 0 !important, but I’d prefer to get to the bottom of this.

Do you have any idea on why this might be happening, or patches that adjust the conditions under which the bottom margin is set? Or could you explain in a little more detail exactly what that code is trying to accomplish and under what specific conditions that bottom margin should be getting set?

Thank you!

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
austinpraycommented, Jun 22, 2018

For posterity:

we had a dumb css rule

.some-container * {
  box-sizing: border-box;
}

That wreaked havoc on codemirror’s margins and such. Set box-sizing back to normal and everything works as expected.

0reactions
benmoshercommented, Jun 6, 2017

FWIW, I had to cram CodeMirror into a tight space but also allow its children to render overflow. Used overflow: visible !important; to get around the referenced overflow: scroll !important; in c818907.

I also explicitly set margin-bottom: 0; and margin-right: 0; to negate the negative margins, and that works fine.

I am using scrollbarStyle: null. Perhaps a future version could update this or add another style (intrinsic size mode?) that has no scrollbars, but instead is intrinsic size. (or maybe I missed a cleaner way to do this?)

Anyway, overriding the margins on CodeMirror-scroll back to 0 is a fine workaround. Mostly mentioning here in case others arrive here via search engine after seeing only n - 1 displayed in their CM instance. 😅

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

CodeMirror-sizer gets unnecessary negative margin-bottom
The margin is not unneccesary -- it compensates for the size of the real (hidden) scrollbar, making sure that the bottom of the...
Read more >
margin-bottom - CSS: Cascading Style Sheets - MDN Web Docs
The margin-bottom property is specified as the keyword auto , or a <length> , or a <percentage> . Its value can be positive,...
Read more >
How do negative margins in CSS work and why is (margin-top
Negative margins are valid in css and understanding their (compliant) behaviour is mainly based on the box model and margin collapsing.
Read more >
The Definitive Guide to Using Negative Margins
If the negative margin is equal to the actual width, then it overlaps it entirely. This is because margins, padding, borders, and width...
Read more >
The Rules of Margin Collapse - Josh W Comeau
By applying an inverse negative margin to the parent, you can "cancel out" a margin. Of course, this is not ideal. Better to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found