How to place two Ivs next to each other in Bootstrap

Asked

Viewed 3,732 times

6

I’m still novice in web development and I’m having a doubt in my form to put the two lines of the form next to each other in responsive Bootstrap, knowing that each input will bring information separately.

Example:

Nome: ________________    Sobrenome: ______________

.group{ 
	position:relative; 
	margin-bottom:20px; 
  }
  .group input 				{
	font-size:18px;
	padding:7px 7px 5px 2px;
	display:block;
	width:80%;
	border:none;
	border-bottom:1px solid #B3AFAF;
  }
  .group input:focus 		{ outline:none; }
  
  /* LABEL ======================================= */
  .group label 				 {
	color:#fff; 
	font-size:18px;
	font-weight:normal;
	position:absolute;
	pointer-events:none;
	left:5px;
	top:10px;
	transition:0.2s ease all; 
	-moz-transition:0.2s ease all; 
	-webkit-transition:0.2s ease all;
  }
  
  /* active state */
  .group input:focus ~ label, input:valid ~ label 		{
	top:-15px;
	font-size:14px;
	color:#5264AE;
  }
  
  /* BOTTOM BARS ================================= */
  .group .bar 	{ position:relative; display:block; width:300px; }
  .group .bar:before, .bar:after 	{
	content:'';
	height:2px; 
	width:0;
	bottom:1px; 
	position:absolute;
	background:#5264AE; 
	transition:0.2s ease all; 
	-moz-transition:0.2s ease all; 
	-webkit-transition:0.2s ease all;
  }
  .group .bar:before {
	left:50%;
  }
  .group .bar:after {
	right:50%; 
  }
  
  /* active state */
  .group input:focus ~ .bar:before, input:focus ~ .bar:after {
	width:50%;
  }
  
  /* HIGHLIGHTER ================================== */
  .group .highlight {
	position:absolute;
	height:60%; 
	width:100px; 
	top:25%; 
	left:0;
	pointer-events:none;
	opacity:0.5;
  }
  
  /* active state */
  .group input:focus ~ .highlight {
	-webkit-animation:inputHighlighter 0.3s ease;
	-moz-animation:inputHighlighter 0.3s ease;
	animation:inputHighlighter 0.3s ease;
  }
  
  /* ANIMATIONS ================ */
  @-webkit-keyframes inputHighlighter {
	  from { background:#5264AE; }
	to 	{ width:0; background:transparent; }
  }
  @-moz-keyframes inputHighlighter {
	  from { background:#5264AE; }
	to 	{ width:0; background:transparent; }
  }
  @keyframes inputHighlighter {
	  from { background:#5264AE; }
	to 	{ width:0; background:transparent; }
  }
<div class="group">
												<input type="number" name="Phone" required="required"style="background-color:transparent"onkeydown="limit(this, 11);" onkeyup="limit(this,11);">
                                                <span class="highlight"></span>
                                                <span class="bar"></span><label>Usuario</label>
											</div>
											
											<div class="group">
												<input type="password" name="password" required="required"><input type="hidden" name="senh" value="Trainer"style="background-color:transparent"onkeydown="limit(this, 4);" onkeyup="limit(this,4);">
                                                <span class="highlight"></span>
                                                <span class="bar"></span><label>Senha</label>

  • you can post all the code.

  • My dear, take a look at this answer, I think it will help you:https://answall.com/questions/235749/centralizar-objetos-dentro-da-div/235751#235751

  • yes Alexandre the example that Voce gave me this right but the rest of the form will be centralized right below. I need something that name and name stand next to each other and the rest centered below.

  • my div are formatted in css3. kkk there is some class I can insert that separates it ?

  • Hello Thalis Alison, welcome to Sopt! It seems that your code is incomplete. I edited your question, but you can improve it by clicking here. Since you’re new, I suggest you see how to ask a good question or if you still have doubts about how the site works, you can make a small tour around here.

3 answers

3

If you are using Bootstrap 4, just set in the div the class .form-Row instead of .Row, thus obtaining more compact layouts.
See more in: https://getbootstrap.com/docs/4.0/components/forms/? #form-Row

Example:

<form>
  <div class="form-row">
    <div class="col">
      <input type="text" class="form-control" placeholder="First name">
    </div>
    <div class="col">
      <input type="text" class="form-control" placeholder="Last name">
    </div>
  </div>
</form>

Another way is to use a Grid system, using columns. Creating a class div .Row and then Ive daughters with the class .col-Sm-##, being col- standard, you must choose to Sm/Md/lg/Xl, to set the moment the columns will move down from each other (responsive feature), and then choose the column ratio, 1 to 12 of 12.

For example .col-Md-6, for two columns (Divs) of the same size in the ratio of 6 and 6 to 12, and another example, 3 columns (Divs) with the class .col-lg-4, for 3 columns of the same size. Recalling that, the Grid system uses 12 as the base size for defining the proportions of columns.

Example:

<div class="row">
  <div class="col-sm-6">seu objeto aqui</div>
  <div class="col-sm-6">seu objeto aqui</div>
</div>

It is very important to read the Bootstrap Framework documentation.
See more in: https://getbootstrap.com/docs/4.0/layout/grid/

0

I think you want to put your Abels next to each other, so here you go, if not this, comment that I edit the answer

<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<title></title> 

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- Início do sript JQuery JS -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Fim do script JQuery JS -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
</script>    

</head>

<div class="row">
    <div class="col-lg-12"><!-- Conteiner Geral -->     

        <div class="panel panel-default"><!-- Inicio Panel Geral -->
            <div class="panel-body"><!-- Corpo Panel  -->

                <!-- Inicio do formulario -->
                <form method="POST" action="">
                    <br>
                    <div class="col-lg-12">
                        <div class="col-lg-4"><!-- Inicio Input Código -->
                            <label for="ex1">Codigo: </label>
                            <input  type="text" class="form-control" id="" name="" size="60"><br>
                        </div><!-- FimInput Código -->
                    </div>

                    <div class="col-lg-12">
                        <div class="col-lg-4"><!-- Inicio Input Usuário -->
                            <label for="ex1">Usuário: </label>
                            <input  type="text"  class="form-control" id="" name="" size="40"><br>
                        </div><!-- Fim Input Usuário -->

                        <div class="col-lg-8"><!-- Inicio Input Senha Antiga -->
                            <label for="ex1">Senha Aniga: </label>
                            <input  type="text"  class="form-control" id="" name="" size="40"><br>
                        </div><!-- Fim Input Senha Antiga -->
                    </div>
            </div>  
        </div>
    </div>
</div>

Resulting in this, see the image below.

inserir a descrição da imagem aqui

  • I’ll put them in and confirm with here

  • so Victor was not I’m using css in the class any change I do it does not execute css does not work and my form is without animation without entering data I will post my css the mr give a look

0

.group{ 
	position:relative; 
	margin-bottom:20px; 
  }
  .group input 				{
	font-size:18px;
	padding:7px 7px 5px 2px;
	display:block;
	width:80%;
	border:none;
	border-bottom:1px solid #B3AFAF;
  }
  .group input:focus 		{ outline:none; }
  
  /* LABEL ======================================= */
  .group label 				 {
	color:#fff; 
	font-size:18px;
	font-weight:normal;
	position:absolute;
	pointer-events:none;
	left:5px;
	top:10px;
	transition:0.2s ease all; 
	-moz-transition:0.2s ease all; 
	-webkit-transition:0.2s ease all;
  }
  
  /* active state */
  .group input:focus ~ label, input:valid ~ label 		{
	top:-15px;
	font-size:14px;
	color:#5264AE;
  }
  
  /* BOTTOM BARS ================================= */
  .group .bar 	{ position:relative; display:block; width:300px; }
  .group .bar:before, .bar:after 	{
	content:'';
	height:2px; 
	width:0;
	bottom:1px; 
	position:absolute;
	background:#5264AE; 
	transition:0.2s ease all; 
	-moz-transition:0.2s ease all; 
	-webkit-transition:0.2s ease all;
  }
  .group .bar:before {
	left:50%;
  }
  .group .bar:after {
	right:50%; 
  }
  
  /* active state */
  .group input:focus ~ .bar:before, input:focus ~ .bar:after {
	width:50%;
  }
  
  /* HIGHLIGHTER ================================== */
  .group .highlight {
	position:absolute;
	height:60%; 
	width:100px; 
	top:25%; 
	left:0;
	pointer-events:none;
	opacity:0.5;
  }
  
  /* active state */
  .group input:focus ~ .highlight {
	-webkit-animation:inputHighlighter 0.3s ease;
	-moz-animation:inputHighlighter 0.3s ease;
	animation:inputHighlighter 0.3s ease;
  }
  
  /* ANIMATIONS ================ */
  @-webkit-keyframes inputHighlighter {
	  from { background:#5264AE; }
	to 	{ width:0; background:transparent; }
  }
  @-moz-keyframes inputHighlighter {
	  from { background:#5264AE; }
	to 	{ width:0; background:transparent; }
  }
  @keyframes inputHighlighter {
	  from { background:#5264AE; }
	to 	{ width:0; background:transparent; }
  }
<div class="group">
												<input type="number" name="Phone" required="required"style="background-color:transparent"onkeydown="limit(this, 11);" onkeyup="limit(this,11);">
                                                <span class="highlight"></span>
                                                <span class="bar"></span><label>Usuario</label>
											</div>
											
											<div class="group">
												<input type="password" name="password" required="required"><input type="hidden" name="senh" value="Trainer"style="background-color:transparent"onkeydown="limit(this, 4);" onkeyup="limit(this,4);">
                                                <span class="highlight"></span>
                                                <span class="bar"></span><label>Senha</label>

  • this and the code is already working where I can put this class to run on mobile?

  • your answer is clearly a copy of the Hugocsl’s response with small changes, you should suggest an issue in his reply and mark it as correct. Don’t post your own answer.

Browser other questions tagged

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