将文本放在boostrap输入旁边不起作用

时间:2018-04-04 06:51:35

标签: html css twitter-bootstrap css3 bootstrap-4

所以我有一个表单,我使用Bootstrap框架,并且在这个表单的每个输入类型上,我想在左边显示文本输入是什么,但是文本在输入之上会发生什么这个:

目前表格的样子: enter image description here

<div class="container">
        <br>
        <center> <h3> Jongere toevoegen </h3> </center>
        <br>
                <?php  echo form_open('index.php/Addjongere/Add_jongere'); ?>
            <form>
                <div class="form-group row">
                 <label>Roepnaam:</label>
                    <input class="form-control" name="roepnaam" id="roepnaam" placeholder="Roepnaam" type="text">
                </div>

                    <div class="form-group row">
                         <label>Tussenvoegsel:</label>
                    <input class="form-control" name="tussenvoegsel" id="tussenvoegsel" placeholder="Tussenvoegsel" type="text">
                </div>

                <div class="form-group row">
                  <label>Achternaam:</label>
                    <input class="form-control" name="achternaam" id="achternaam" placeholder="Achternaam" type="text">
                </div>

                <div>
                    <button class="btn btn-primary" name="Add_jongere" >Toevoegen</button>
                </div>
            </form>       
        </div>

有谁知道我能做什么? 任何形式的帮助表示赞赏

3 个答案:

答案 0 :(得分:0)

这是你想要得到的吗?从表单和表单组div中删除class="form-inline"添加类row

我还在表单周围添加了一个容器,以使其保持良好的尺寸。

修改
我忘了在标签上添加class="col-sm-4",在输入中添加class="form-control col-sm-8"。所以他们不是彼此相邻的。

&#13;
&#13;
label{
  text-align: center;
}

h3, .container button{
  display: block;
  margin: 0 auto;
  text-align: center;
}
&#13;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<div class="container">
      <h3> Jongere toevoegen </h3>
    <br>
    <form>
      <div class="form-group row">
        <label class="col-sm-4">Roepnaam:</label>
        <input class="form-control col-sm-8" name="roepnaam" id="roepnaam" placeholder="Roepnaam" type="text">
      </div>

      <div class="form-group row">
        <label class="col-sm-4">Tussenvoegsel:</label>
        <input class="form-control col-sm-8" name="tussenvoegsel" id="tussenvoegsel" placeholder="Tussenvoegsel" type="text">
      </div>

      <div class="form-group row">
        <label class="col-sm-4">Achternaam:</label>
        <input class="form-control col-sm-8" name="achternaam" id="achternaam" placeholder="Achternaam" type="text">
      </div>

      <div>
        <button class="btn btn-primary" name="Add_jongere">Toevoegen</button>
      </div>
    </form>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您可以将整个表单放在响应col中,并相应地调整标签/输入宽度......

https://www.codeply.com/go/vdQSHJUalP

<div class="container">
    <div class="row">
        <form class="col-12 col-md-8 mx-auto">
            <div class="form-group row">
                <label class="col-5 col-sm-3 text-truncate">Roepnaam:</label>
                <input class="form-control col" name="roepnaam" id="roepnaam" placeholder="Roepnaam" type="text">
            </div>
            <div class="form-group row">
                <label class="col-5 col-sm-3 text-truncate">Tussenvoegsel:</label>
                <input class="form-control col" name="tussenvoegsel" id="tussenvoegsel" placeholder="Tussenvoegsel" type="text">
            </div>
            <div class="form-group row">
                <label class="col-5 col-sm-3 text-truncate">Achternaam:</label>
                <input class="form-control col" name="achternaam" id="achternaam" placeholder="Achternaam" type="text">
            </div>
            <div class="form-group row">
                <div class="col-12 text-center">
                    <button class="btn btn-primary" name="Add_jongere">Toevoegen</button>
                </div>
            </div>
        </form>
    </div>
</div>

答案 2 :(得分:-1)

试试这个:

.formcontrol {width: 50%; float:right;}