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

181
Visualizações
Is there a way I can get the table to not resize in height when I innerHtml something in the "td"?

I am sorry for the norwegian variable names in the js file, but if u try to click a cell, you will see that the height of it will resize, I am wondering if anyone have an easy and quick change!

<!doctype html>
<html lang="no">
 <head> 
    <title> Standardoppsett </title>
    <meta charset="utf-8">
 </head>
 
<style>

.board {
  table-layout: fixed;
  width: 360px;
  height: 360px;
  border: 32px solid;
  border-color: darkslategray;
  border-radius: 5px;
}
.firkant {
  border: 1px black solid;
}
.hvit{
  background:white;
}
.svart{
  background:grey;
}
td:hover {
  background: lightgreen;
  cursor: pointer
}

</style>

<body>

<div>

<table class="board"></table>

</div>

<script>

let tableEl = document.querySelector("table")

for(let i = 1; i < 9; i++) {
  let trEl = document.createElement('tr');
  for(let j = 1; j < 9; j++) {
    let tdEl = document.createElement('td');
    tdEl.setAttribute("id","rute"+i+j)
    tdEl.addEventListener("click",plasserDronning)
    trEl.appendChild(tdEl);
    // Bare på grunn av css
    tdEl.className = (i%2 === j%2) ? "hvit firkant" : "svart firkant";
    }
  tableEl.appendChild(trEl);
}

turTeller = 0

function plasserDronning(e){
  let firkantTrykket = e.target
  console.log(firkantTrykket.id)
  if (turTeller == 0) {
    if(firkantTrykket = e.target){
      firkantTrykket.innerHTML = "a";
  }
    turTeller = 1
  }
  else if(turTeller == 1) {
    if(firkantTrykket = e.target){
      firkantTrykket.innerHTML = "b";
  }
    turTeller = 2
  }
}


</script>
</body>
</html>

So far I have tried basically everything I am aware of, I have tried to set the table layout to fixed, I have tried to set the "td's" posistion to top and a lot more, if anyone knows what I can do, it would mean a lot!

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

0

In above code I suggest to add height properties in you td tag's class that will solve your issue. if you want to more responsive and you can write media queries.or using other framework like bootstap.

.hvit{
  background:white;
  height:20px;
}
.svart{
  background:grey;
  height:20px;
}
about 4 years ago · Juan Pablo Isaza Relatório

0

You can add height:calc(100% / 8); to the firkant (td) class to prevent the cell from growing.

This way the cell will scale with the table if you decide to increase the table size or make it dynamic.

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