Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

89
Vistas
Сodemirror does not set the height to 100%

I use this code

Initialize new codemirror element in HTML/JS:

<body>
<div id="code"></div>

<script>
    var editor = CodeMirror(document.getElementById('code'), {
        lineNumbers: true,
        lineWrapping: false,
        matchBrackets: true,
        closeBrackets: true,
        autoCloseBrackets: true,
        styleActiveLine: true,
        mode: "text/x-csrc",
    });
</script>
</body>

Set height for codemirror in CSS:

.CodeMirror {
    font-size: 1em;
    float: left;
    width: 100%; 
    height: 100%;
}
.cm-wrap { height: 100% }
.cm-scroller { overflow: auto }

But codemirror only fills 50% of the height. Why and how to fix this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It looks like you missed some styles for the page. If you use the following CSS, CodeMirror will take 100% height and width.

    html {
        height: 100%;
        width: 100%;
        min-width: 100%;
        min-height: 100%;
    }

    body {
        height: 100%;
        width: 100%;
    }

    #code {
        height: 100%;
        width: 100%;
    }

    .CodeMirror {
        font-size: 1em;
        float: left;
        width: 100%;
        height: 100%;
    }

    .cm-wrap {
        height: 100%
    }

    .cm-scroller {
        overflow: auto
    }

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Test</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
        charset="utf-8">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.62.3/codemirror.min.css"
        integrity="sha512-6sALqOPMrNSc+1p5xOhPwGIzs6kIlST+9oGWlI4Wwcbj1saaX9J3uzO3Vub016dmHV7hM+bMi/rfXLiF5DNIZg=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
    <style>
        html {
            height: 100%;
            width: 100%;
            min-width: 100%;
            min-height: 100%;
        }

        body {
            height: 100%;
            width: 100%;
        }

        #code {
            height: 100%;
            width: 100%;
        }

        .CodeMirror {
            font-size: 1em;
            float: left;
            width: 100%;
            height: 100%;
        }

        .cm-wrap {
            height: 100%
        }

        .cm-scroller {
            overflow: auto
        }
    </style>
</head>

<body>
    <div id="code"></div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.62.3/codemirror.min.js"
        integrity="sha512-hGVnilhYD74EGnPbzyvje74/Urjrg5LSNGx0ARG1Ucqyiaz+lFvtsXk/1jCwT9/giXP0qoXSlVDjxNxjLvmqAw=="
        crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    <script>
        var editor = CodeMirror(document.getElementById('code'), {
            lineNumbers: true,
            lineWrapping: false,
            matchBrackets: true,
            closeBrackets: true,
            autoCloseBrackets: true,
            styleActiveLine: true,
            mode: "text/x-csrc",
        });
    </script>
</body>

</html>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda