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

163
Visualizações
Print a list of number in a bootsrap button with equal height and width

I want to display the number of days in a specific month within the bootstrap button. Using the code below didn't distribute the button in an equal height and width.

I want to display the number similarly as shown in the screenshot, with a fixed number of buttons in a row, it need not be exact seven but the number should be distributed equally.

enter image description here

const [day, month, year] = "18/03/2022".split("/");

const getAllDaysInMonth = (month, year) =>
  Array.from({
      length: new Date(year, month, 0).getDate()
    }, // get next month, zeroth's (previous) day
    (_, i) => new Date(year, month - 1, i + 1) // get current month (0 based index)
  );

const allDatesInOctober = getAllDaysInMonth(month, year);

const allDateinMonth = allDatesInOctober.map(x => x.toLocaleDateString([], {
  day: "numeric"
}));

const list = document.getElementById('year-of-day');

window.onload = () => {
  list.innerHTML = allDateinMonth.map(i => `<button type="button" class="btn btn-info m-2">${i}</button>`).join('');
};
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row rowSpacing">
  <div class="col-md-12">
    <div class="form-group col-md-12">
      <label for="inputEmail4">Select Dates</label>
      <div class="input-group" id="year-of-day">
        <button type="button" class="btn btn-info m-2"> </button>
      </div>
    </div>
  </div>
</div>

How should I approach this problem?

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

0

It doesn't align good because the width changes as some of the numbers are single digit while other are double digit. Set a base width which all the buttons will have, as the following:

const [day, month, year] = "18/03/2022".split("/");

const getAllDaysInMonth = (month, year) =>
  Array.from({
      length: new Date(year, month, 0).getDate()
    }, // get next month, zeroth's (previous) day
    (_, i) => new Date(year, month - 1, i + 1) // get current month (0 based index)
  );

const allDatesInOctober = getAllDaysInMonth(month, year);

const allDateinMonth = allDatesInOctober.map(x => x.toLocaleDateString([], {
  day: "numeric"
}));

const list = document.getElementById('year-of-day');

window.onload = () => {
  list.innerHTML = allDateinMonth.map(i => `<button type="button" class="btn btn-info m-2" style="width: 50px">${i}</button>`).join('');
};
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row rowSpacing">
  <div class="col-md-12">
    <div class="form-group col-md-12">
      <label for="inputEmail4">Select Dates</label>
      <div class="input-group" id="year-of-day">
        <button type="button" class="btn btn-info m-2"> </button>
      </div>
    </div>
  </div>
</div>

All I added in the above is style="width: 50px".

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