How to change the layout of Radio Buttons in the responsive layout with Bootstrap or another tool?

Asked

Viewed 32 times

-2

Currently when the site is in mobile mode/reduced to a certain resolution the Radio Buttons automatically position themselves as follows:

inserir a descrição da imagem aqui

I’d like it to look something like this:

inserir a descrição da imagem aqui

Part of the HTML code:

 <div class="row" style="padding-left: 15%;">

                <div class="col-sm-2">

                    <input type="radio" id="1" name="quartos" value="1" class="RadionQuarto">
                    <label for="1">1</label><br>

                </div>

                <div class="col-sm-2">

                    <input type="radio" id="2" name="quartos" value="2" class="RadionQuarto">
                    <label for="2">2</label><br>

                </div>

                <div class="col-sm-2">
                    <input type="radio" id="3" name="quartos" value="3" class="RadionQuarto">
                    <label for="3">3</label><br>

                </div>
                <div class="col-sm-2">
                    <input type="radio" id="4" name="quartos" value="4" class="RadionQuarto">
                    <label for="4">4</label><br>

                </div>
                <div class="col-sm-2">

                    <input type="radio" id="5" name="quartos" value="5" class="RadionQuarto">
                    <label for="5">5</label><br>

                </div>

            </div>

1 answer

1


Face is just change col-sm-2 by just col-2 so they’ll never get down from each other and stay in the same line. Since you are using Bootstrap, I strongly suggest you study the classes of Grid his https://getbootstrap.com/docs/4.4/layout/grid/

inserir a descrição da imagem aqui

Code of the image above:

<link rel="stylesheet" type="text/css" media="screen" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />

<div class="row" style="padding-left: 15%;">

  <div class="col-2">

      <input type="radio" id="1" name="quartos" value="1" class="RadionQuarto">
      <label for="1">1</label><br>

  </div>

  <div class="col-2">

      <input type="radio" id="2" name="quartos" value="2" class="RadionQuarto">
      <label for="2">2</label><br>

  </div>

  <div class="col-2">
      <input type="radio" id="3" name="quartos" value="3" class="RadionQuarto">
      <label for="3">3</label><br>

  </div>
  <div class="col-2">
      <input type="radio" id="4" name="quartos" value="4" class="RadionQuarto">
      <label for="4">4</label><br>

  </div>
  <div class="col-2">

      <input type="radio" id="5" name="quartos" value="5" class="RadionQuarto">
      <label for="5">5</label><br>

  </div>

</div>

  • vlw, I’ll take a look

  • @Fernando if it works out remember to mark the answer as accepted by clicking on the icon just below the arrows next to the answer, so it is not pending even though it has been solved!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.