How to add padding-top for Monaco editor?
Asked Answered
W

2

11

How can I add padding between the first line of code and top border of Monaco editor?

I have this:

enter image description here

But I need something like this:

enter image description here

Wildman answered 4/7, 2018 at 14:0 Comment(3)
Possible duplicate of adding a padding to monaco editor area (lines content)Mullins
Add padding: { top: 25 } as one of your monaco optionsHamby
Note to readers: padding was not introduced until v0.21.0Jorgejorgensen
O
6

A little late to the party, but this initial option is available (monaco v0.41.0):

const options = {
    padding: {
        top: 10
    }
    // more options...
}
monaco.editor.create(anElement, options);

See: IEditorPaddingOptions

Olmsted answered 3/10, 2023 at 15:22 Comment(0)
R
2

Try

.monaco-editor {
 padding-top: 15px;
}

It worked for me

Redmond answered 18/5, 2020 at 1:5 Comment(5)
Interesting that this got downvoted but the comment from @Mullins links to a similar answer... I can confirm this works :)Redmond
This did not work for me; if you have the height set and also do the above, the child overflow-guard stays its same height but is just pushed down 15px.Jorgejorgensen
this will disable the popups when you hover over the code.Korwun
This did not work for me as the background of the editor was also shifted from the padding, not just the text content. Using the padding of the editor options worked well.Tramline
This caused an infinite loop for us. Monaco tried to keep resizing the editor, seems like this will mess with their calculations.Aggappe

© 2022 - 2024 — McMap. All rights reserved.