Created
January 10, 2017 12:45
-
-
Save kui/2053b5d8eddbf4f35035662c5b7be6ab to your computer and use it in GitHub Desktop.
Manually resize CodeMirror using only CSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.22.0/codemirror.css"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.22.0/codemirror.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.22.0/mode/css/css.js"></script> | |
<style> | |
#cm-wrapper { | |
overflow: hidden; | |
resize: both; | |
border: 1px black solid; | |
width: 300px; | |
height: 200px; | |
padding: 0 10px 10px 0; | |
/* background-color: #ddd; */ | |
} | |
.CodeMirror { | |
border-right: grey 1px solid; | |
border-bottom: grey 1px solid; | |
width: 100%; | |
height: 100%; | |
overflow: hidden; | |
} | |
</style> | |
<div id="cm-wrapper"></div> | |
<textarea name="css"> | |
/* foo */ | |
</textarea> | |
<script> | |
const t = document.getElementsByName("css")[0]; | |
t.style.display = "none"; | |
const w = document.getElementById("cm-wrapper"); | |
CodeMirror(w, { | |
value: t.value, | |
onChange: (e) => t.textContent = e.getValue(), | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment