Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

169
Visualizações
Centering Image with centre align clashing with Position In CSS

I am new to html and css and recently I started making a canvas game. I wish to have an image and align it in the centre of the canvas with HTML. I used the 'position: Absolute' property and could at least put it on the canvas but when I used the 'text-align: centre' property, my position property stopped working and came below the canvas.

So I wanted to know, how I can centre my image on the canvas.

CSS

#startgameimg{
    text-align:center;
    width: 50px;
    display:block;
    margin:auto;    
    position: absolute;
    cursor: pointer;
    
}

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>GAME</title>

    <link href = "style.css" rel = "stylesheet">
</head>
<body>
    
    <div style = "text-align: center;">    
        <canvas 
            id = "canvas" 
            height = "560"
            width = "800"
            style = "border:5px solid rgb(33, 8, 61)"
            >Your Browser is Not Supported</canvas>

            <div id = 'start'>
                <img src = "play.png" alt = "" id = "startgameimg"/>
            </div>
    </div>
    <script src = "script.js" ></script>
</body>
</html>

Please Note: I went through about 5 to 6 Stack Overflow questions regarding the same topic but couldn't find any solution

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

#startgameimg{
    text-align:center;
    width: auto;
    display:block;
    margin:auto;    
    position: absolute;
    cursor: pointer;
    top:50%;
    left:50%;
    transform:translate(-50%, -50%)
    
}
 <div style = "text-align: center; position: reletive">    
        <canvas 
            id = "canvas" 
            height = "560"
            width = "800"
            style = "border:5px solid rgb(33, 8, 61)"
            >Your Browser is Not Supported</canvas>

            <div id = 'start'>
                <img src = "play.png" alt = "MY IMG" id = "startgameimg"/>
            </div>
    </div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda