How to make an HTML form stay responsive

1

I have an HTML and CSS form that is perfect on my site, but when I try to open it on a mobile device (mobile phone or tablet) it gets totally distorted. I'm using Bootstrap as a CSS framework.

My code:

.tudo-border-box {
		    box-sizing: border-box;
		}
		
		 
		.header-urna {
			border: solid;
		    background-color: #565656;
		    padding: 30px;
		    text-align: center;
		    font-size: 35px;
		    color: white;
		}
		 
		.nav-urna {
		    float: right;
		    width: 30%;
		    border: solid;
		    height: 400px; /* only for demonstration, should be removed */
		    background: #565656;
		    color: white;
		    padding: 20px;
		}
		

		.nav-urna ul {
		    list-style-type: none;
		    padding: 0;
		}
		
		.article-urna {
		    float: left;
		    padding: 20px;
		    /* border: solid; */
		    width: 70%;
		    background-color: #f1f1f1;
		    height: 400px; /* only for demonstration, should be removed */
		}
		 
		.section-urna:after {
		    content: "";
		    display: table;
		    clear: both;
		}
		 
		.footer-urna {
			border: solid;
		    background-color: #565656;
		    padding: 10px;
		    text-align: center;
		    color: white;
		}
		
		@media (max-width: 600px) {
		    .nav-urna, .article-urna {
		        width: 100%;
		        height: auto;
		    }
		}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><linkhref="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>


<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script><divid="urnaDigital" class="form-control" style="border: solid;">
	        <header class="tudo-border-box header-urna">
	  			<h2 class="tudo-border-box">Urna Digital</h2>
			</header>
			
			<section class="tudo-border-box section-urna">
			
			<article class="tudo-border-box article-urna">
			    <h1 class="tudo-border-box">Digite o numero do seu candidato</h1>
			    <!-- Aqui vao dois quadrados, um para cada numero, depois que digitado os dois numeros, busco o candidato, caso não existir o numero na base de dados pergunto se o usuario quer anular voto, caso existir, dou a opção de confirmar ou corrigir, caso for clicado o botão branco entao vou pra tela de confirmar ou corrigir, e caso clicar no corrigir, limpo os dois campos de numeros.
			    <br>			    
			    Um ajuste que tenho que fazer, é para celular, botoes de numero ficam  zuados.
			    <br>
			    alem de ver uns erros do console f12 -->
			    
			    <div id="numerosCandidato" class="row" style="height:280px;">
			    	<div class="col-sm-2">
			    	</div>
			    	<div class="col-sm-2">
			    	</div>
			    	<div class="col-sm-2" id="digito1" style="border:solid; font-size: 170px;">
 				    </div>
 					<div class="col-sm-1">
			    	</div>
				    <div class="col-sm-2" id="digito2" style="border:solid; font-size: 170px;">
 			    	</div>
			    	<div class="col-sm-2">
			    	</div>
			    	<div class="col-sm-1">
			    	</div>
			    </div>
			    
			  </article>
			
			  <nav class="tudo-border-box nav-urna">
			     
			      <div class="row">
		          <!--  <div class="btn-group"> -->
		           <div class="col-sm-4" >
					  <button type="button" id="btn1" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">1</button>
					 </div>
					  <div class="col-sm-4" >
					  <button type="button"  id="btn2" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">2</button>
					 </div>
					  <div class="col-sm-4" >
					  <button type="button" id="btn3"  class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">3</button>
					 </div>
					<!-- </div>  -->
				</div> 	
				
				<br>
				
				<div class="row">	
					<div class="col-sm-4" >
					  <button type="button"  id="btn4" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">4</button>
					 </div>
					  <div class="col-sm-4" >
					  <button type="button"  id="btn5" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">5</button>
					 </div>
					  <div class="col-sm-4" >
					  <button type="button" id="btn6"  class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">6</button>
					 </div>
					 
				</div> 	
				
				<br>
				
				<div class="row">	 
					<div class="col-sm-4" >
					  <button type="button" id="btn7"  class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">7</button>
					 </div>
					  <div class="col-sm-4" >
					  <button type="button" id="btn8"  class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">8</button>
					 </div>
					  <div class="col-sm-4" >
					  <button type="button"  id="btn9" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">9</button>
					 </div>
					 
				</div> 
				
				<br>
				
				<div class="row">	
					<div class="col-sm-4" >
 					 </div>
					  <div class="col-sm-4" >
					  <button type="button"  id="btn0" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">0</button>
					 </div>
					  <div class="col-sm-4" >
 					 </div>
				</div>
				
				<div class="row">	
					<br>
				</div>
				
				<div class="row">	
					<div class="btn-group">
					 
					  <button type="button" class="btn btn-default "  id="btnBranco" >BRANCO</button>
					    
					  <button type="button" class="btn btn-warning "  id="btnCorrige"  style="background-color: #fb3f14; border-color: #fb3f14;">CORRIGE</button>
					   
					  <button type="button" class="btn btn-success "  id="btnConfirma" >CONFIRMA</button>
					 
					</div> 
				</div>
				     
			  </nav>
			  
			  
			</section>
			
			<footer class="tudo-border-box footer-urna">
			  <p class="tudo-border-box">
			    Esse simulador funciona da mesma forma que uma urna eletronica,
			     você digita o numero de seu candidato a presidencia e pressionar Confirma.
			     Caso digitou o numero errado clique em Corrige.
			     Caso desejar votar em branco, clique em Branco.
			     </p>
			</footer> 
		</div>
    
asked by anonymous 30.08.2018 / 03:10

2 answers

1
Basically you have to change the col- of the btns from col-md-4 to col-xs-4 because using XS vc ensures that the columns will continue to be divided evenly on small screens without putting a btn on each line as is happening in your code.

See the example below to see how it looks.

 .tudo-border-box {
		    box-sizing: border-box;
		}
		
		 
		.header-urna {
			border: solid;
		    background-color: #565656;
		    padding: 30px;
		    text-align: center;
		    font-size: 35px;
		    color: white;
		}
		 
		.nav-urna {
		    float: right;
		    width: 30%;
		    border: solid;
		    height: 400px; /* only for demonstration, should be removed */
		    background: #565656;
		    color: white;
		    padding: 20px;
		}
		

		.nav-urna ul {
		    list-style-type: none;
		    padding: 0;
		}
		
		.article-urna {
		    float: left;
		    padding: 20px;
		    /* border: solid; */
		    width: 70%;
		    background-color: #f1f1f1;
		    height: 400px; /* only for demonstration, should be removed */
		}
		 
		.section-urna:after {
		    content: "";
		    display: table;
		    clear: both;
		}
		 
		.footer-urna {
			border: solid;
		    background-color: #565656;
		    padding: 10px;
		    text-align: center;
		    color: white;
		}
		
		@media (max-width: 600px) {
		    .nav-urna, .article-urna {
		        width: 100%;
		        height: auto;
		    }
		}
<link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />    

    <div id="urnaDigital" class="form-control" style="border: solid;">
        <header class="tudo-border-box header-urna">
        <h2 class="tudo-border-box">Urna Digital</h2>
    </header>
    
    <section class="tudo-border-box section-urna">
    
    <article class="tudo-border-box article-urna">
        <h1 class="tudo-border-box">Digite o numero do seu candidato</h1>
        <!-- Aqui vao dois quadrados, um para cada numero, depois que digitado os dois numeros, busco o candidato, caso não existir o numero na base de dados pergunto se o usuario quer anular voto, caso existir, dou a opção de confirmar ou corrigir, caso for clicado o botão branco entao vou pra tela de confirmar ou corrigir, e caso clicar no corrigir, limpo os dois campos de numeros.
        <br>			    
        Um ajuste que tenho que fazer, é para celular, botoes de numero ficam  zuados.
        <br>
        alem de ver uns erros do console f12 -->
        
        <div id="numerosCandidato" class="row" style="height:280px;">
          <div class="col-sm-2">
          </div>
          <div class="col-sm-2">
          </div>
          <div class="col-sm-2" id="digito1" style="border:solid; font-size: 170px;">
           </div>
         <div class="col-sm-1">
          </div>
          <div class="col-sm-2" id="digito2" style="border:solid; font-size: 170px;">
           </div>
          <div class="col-sm-2">
          </div>
          <div class="col-sm-1">
          </div>
        </div>
        
      </article>
    
      <nav class="tudo-border-box nav-urna">
         
          <div class="row">
            <!--  <div class="btn-group"> -->
             <div class="col-xs-4" >
          <button type="button" id="btn1" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">1</button>
         </div>
          <div class="col-xs-4" >
          <button type="button"  id="btn2" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">2</button>
         </div>
          <div class="col-xs-4" >
          <button type="button" id="btn3"  class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">3</button>
         </div>
        <!-- </div>  -->
      </div> 	
      
      <br>
      
      <div class="row">	
        <div class="col-xs-4" >
          <button type="button"  id="btn4" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">4</button>
         </div>
          <div class="col-xs-4" >
          <button type="button"  id="btn5" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">5</button>
         </div>
          <div class="col-xs-4" >
          <button type="button" id="btn6"  class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">6</button>
         </div>
         
      </div> 	
      
      <br>
      
      <div class="row">	 
        <div class="col-xs-4" >
          <button type="button" id="btn7"  class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">7</button>
         </div>
          <div class="col-xs-4" >
          <button type="button" id="btn8"  class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">8</button>
         </div>
          <div class="col-xs-4" >
          <button type="button"  id="btn9" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">9</button>
         </div>
         
      </div> 
      
      <br>
      
      <div class="row">	
        <div class="col-sm-4" >
          </div>
          <div class="col-sm-4" >
          <button type="button"  id="btn0" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">0</button>
         </div>
          <div class="col-sm-4" >
          </div>
      </div>
      
      <div class="row">	
        <br>
      </div>
      
      <div class="row">	
        <div class="btn-group">
         
          <button type="button" class="btn btn-default "  id="btnBranco" >BRANCO</button>
            
          <button type="button" class="btn btn-warning "  id="btnCorrige"  style="background-color: #fb3f14; border-color: #fb3f14;">CORRIGE</button>
           
          <button type="button" class="btn btn-success "  id="btnConfirma" >CONFIRMA</button>
         
        </div> 
      </div>
           
      </nav>
      
      
    </section>
    
    <footer class="tudo-border-box footer-urna">
      <p class="tudo-border-box">
        Esse simulador funciona da mesma forma que uma urna eletronica,
         você digita o numero de seu candidato a presidencia e pressionar Confirma.
         Caso digitou o numero errado clique em Corrige.
         Caso desejar votar em branco, clique em Branco.
         </p>
    </footer> 
  </div>

NOTE: Regardless of this you still need to make some CSS CSS adjustments in btn-group

    
30.08.2018 / 03:56
1

Friend, the col-sm tag is for mobile devices so fine, but you create your html totally on top of it, you should use the responsiveness tags for each screen size, for example when the device is desktop it will open the entire screen when it is on a phone, use the input area underneath or above the screen, in case your code only uses a single size for all screens.

I recommend reading this article .

    
30.08.2018 / 03:47