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

200
Vistas
How do you put text to the right or left of a canvas element?

I am trying to add text to the right and left of the canvas (black grid) shown in this picture, but no matter what I try it seems to put the text above or below it.

<div id="inputs">
    <input id='slider' type="range" min=2 max=100 step=1>
    Rows: <span id="choice"></span>

    <input id='slider2' type="range" min=0 max=70 step = 0.5>
    Percent of nodes to be walls: <span id="choice2"></span>

    <input type="checkbox" id='Show Path' checked=true>Show Path

    <input type="button" value="Clear Board" onclick="setup();">

    <a href="controls.html" style="margin-left:30px">Controls</a>
  </div>
  <br>
  <canvas id="canvas" width="700" height="700"></canvas>

enter image description here

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

0

Not sure how much content you would like to add on the left/right of the canvas element but I would suggest something like:

<div class="container">
    <div>Left text....</div>
    <canvas id="canvas" width="700" height="700"></canvas>
    <div>Right text....</div>
</div>

With the following CSS:

.container {display: flex; flex-direction: "row"; }
about 4 years ago · Juan Pablo Isaza Denunciar

0

Just needed to add some more css to make it within a line.

EDIT:

The revised snippet can now be run, with the new inline-block-centered class applied to the canvas and surrounding text.

(The canvas border is just to make the canvas visible in the snippet.)

/* This ruleset is just for the snippet. (IRL, reset to 700px) */
#canvas { width: 200px; height: 200px; border: 1px solid grey; }

/* This crucial ruleset puts the selected elements inline together */
.inline-block-centered { display: inline-block; vertical-align: middle; }

/* These rulesets are optional replacements for forced formatting in HTML */
#inputs { margin-bottom: 1em; }
#inputs > a { margin-left: 30px; }
<div id="inputs">
    <input id='slider' type="range" min=2 max=100 step=1>
    Rows: <span id="choice"></span>

    <input id='slider2' type="range" min=0 max=70 step = 0.5>
    Percent of nodes to be walls: <span id="choice2"></span>

    <input type="checkbox" id='Show Path' checked=true>Show Path

    <input type="button" value="Clear Board" onclick="setup();">

    <a href="controls.html">Controls</a>
</div>

<div class="inline-block-centered">
    <span>Left text</span>
</div>

<canvas id="canvas" class="inline-block-centered"></canvas>

<div class="inline-block-centered">
    <span>Right text</span>
</div>

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