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

221
Visualizações
¿Cómo puedo centrar horizontalmente estos 3 botones?

Al principio había 4 botones, solo quería 3, así que eliminé el cuarto y es por eso que quiero que los 3 restantes se vean centrados horizontalmente, se ve raro debido al espacio en blanco del cuarto botón. Intenté algunas cosas pero no funcionaron.

 var tabButtons = document.querySelectorAll(".tabContainer .buttonContainer button"); var tabPanels = document.querySelectorAll(".tabContainer .tabPanel"); function showPanel(panelIndex, colorCode) { tabButtons.forEach(function(node) { node.style.backgroundColor = ""; node.style.color = ""; }); tabButtons[panelIndex].style.backgroundColor = colorCode; tabButtons[panelIndex].style.color = "white"; tabPanels.forEach(function(node) { node.style.display = "none"; }); tabPanels[panelIndex].style.display = "block"; tabPanels[panelIndex].style.backgroundColor = colorCode; } showPanel(0, '#f44336');
 .title { color: #dc2d5e; text-align: center; } .tabContainer { width: 100%; height: 350px; } .tabContainer .buttonContainer { height: 15%; align-items: center; align-content: center; justify-content: center; text-align: center; } .tabContainer .buttonContainer button { width: 25%; height: 100%; float: left; border: none; outline: none; cursor: pointer; padding: 10px; font-family: sans-serif; font-size: 18px; background-color: #eee; } .tabContainer .buttonContainer button:hover { background-color: #d7d4d4; } .tabContainer .tabPanel { height: 85%; background-color: gray; color: white; text-align: center; padding-top: 105px; box-sizing: border-box; font-family: sans-serif; font-size: 22px; display: none; }
 <h1 class="title">Recieved Data</h1> <div class="tabContainer"> <div class="buttonContainer"> <button onclick="showPanel(0,'#f44336')">Feedbacks</button> <button onclick="showPanel(1,'#4caf50')">Suggestions</button> <button onclick="showPanel(2,'#2196f3')">Messages</button> </div> <div class="tabPanel">Tab 1:Content</div> <div class="tabPanel">Tab 2:Content</div> <div class="tabPanel">Tab 3:Content</div> </div>

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

0

Está muy cerca, agregando estas dos propiedades flexibles puede obtener la solución deseada:

 .tabContainer .buttonContainer{ display: flex; justify-content: space-between; } 

 .title{ color: #dc2d5e; text-align: center; } .tabContainer{ width: 100%; height: 350px; } .tabContainer .buttonContainer{ display: flex; height: 15%; align-items: center; align-content: center; justify-content: space-between; text-align: center; } .tabContainer .buttonContainer button{ width: 25%; height: 100%; float: left; border: none; outline:none; cursor: pointer; padding: 10px; font-family: sans-serif; font-size: 18px; background-color: #eee; } .tabContainer .buttonContainer button:hover{ background-color: #d7d4d4; } .tabContainer .tabPanel{ height: 85%; background-color: gray; color: white; text-align: center; padding-top: 105px; box-sizing: border-box; font-family: sans-serif; font-size: 22px; display: none; }
 <h1 class="title">Recieved Data</h1> <div class="tabContainer"> <div class="buttonContainer"> <button onclick="showPanel(0,'#f44336')">Feedbacks</button> <button onclick="showPanel(1,'#4caf50')">Suggestions</button> <button onclick="showPanel(2,'#2196f3')">Messages</button> </div> <div class="tabPanel">Tab 1:Content</div> <div class="tabPanel">Tab 2:Content</div> <div class="tabPanel">Tab 3:Content</div> </div>

¡Esta guía de flexbox es mi opción cada vez que me encuentro con este tipo de problema!

about 4 years ago · Juan Pablo Isaza Relatório

0

Como ahora solo hay 3 botones, haría que el ancho de cada uno fuera un tercio.

Puedes lograr esto haciendo:

 .tabContainer .buttonContainer button{ width: calc(100% / 3); }

EDITAR: Entonces se vería así:

 var tabButtons = document.querySelectorAll(".tabContainer .buttonContainer button"); var tabPanels = document.querySelectorAll(".tabContainer .tabPanel"); function showPanel(panelIndex, colorCode) { tabButtons.forEach(function(node) { node.style.backgroundColor = ""; node.style.color = ""; }); tabButtons[panelIndex].style.backgroundColor = colorCode; tabButtons[panelIndex].style.color = "white"; tabPanels.forEach(function(node) { node.style.display = "none"; }); tabPanels[panelIndex].style.display = "block"; tabPanels[panelIndex].style.backgroundColor = colorCode; } showPanel(0, '#f44336');
 .title { color: #dc2d5e; text-align: center; } .tabContainer { width: 100%; height: 350px; } .tabContainer .buttonContainer { height: 15%; align-items: center; align-content: center; justify-content: center; text-align: center; } .tabContainer .buttonContainer button { width: calc(100% / 3); height: 100%; float: left; border: none; outline: none; cursor: pointer; padding: 10px; font-family: sans-serif; font-size: 18px; background-color: #eee; } .tabContainer .buttonContainer button:hover { background-color: #d7d4d4; } .tabContainer .tabPanel { height: 85%; background-color: gray; color: white; text-align: center; padding-top: 105px; box-sizing: border-box; font-family: sans-serif; font-size: 22px; display: none; }
 <h1 class="title">Recieved Data</h1> <div class="tabContainer"> <div class="buttonContainer"> <button onclick="showPanel(0,'#f44336')">Feedbacks</button> <button onclick="showPanel(1,'#4caf50')">Suggestions</button> <button onclick="showPanel(2,'#2196f3')">Messages</button> </div> <div class="tabPanel">Tab 1:Content</div> <div class="tabPanel">Tab 2:Content</div> <div class="tabPanel">Tab 3:Content</div> </div>

calc() es ampliamente compatible con los navegadores modernos.

about 4 years ago · Juan Pablo Isaza Relatório

0

¡Solo necesitas agregar esto a tu css!

 .buttonContainer{ display: flex; }
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