How to make an HTML form responsive

Asked

Viewed 1,166 times

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 or tablet) it is totally distorted. I am 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>

<link href="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>


<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-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>

  • 1

    Man, you can do the following... Use bootstrap, done responded, but also you can use instead of pixels with measure you can use relative measures, done: % vw, vh... Take a look at http://developmentoparaweb.com/css/unidades-css-rem-vh-vw-vmin-vmaxex-ch/

2 answers

1

Buddy, the col-Sm tag is for mobile devices so far 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 whole screen, when he is on a phone, use the input area below or above the screen, in case your code only uses a single size for all screens.

I recommend reading this article.

  • thanks for the tips bro!!

  • Come on, man, we’re all here for this :D

1


Basically you have to change the col- of btns of col-md-4 for col-xs-4 because using XS vc ensures that the columns will continue to be divided correctly even into small screens, without putting a btn in each row 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>

OBS: Regardless you still need to make some CSS type adjustments in btn-group

  • Thanks for the help bro, was exactly what needed to leave the buttons side by side and worked perfectly!

  • 1

    @sergioBertolazzo tranquil young tmj! Success with the project ai

Browser other questions tagged

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