HTML Bootstrap表单样式

时间:2018-05-18 18:15:37

标签: html css asp.net bootstrap-4

如何让这个列表显示文本框上方的按钮?如在

Ideal formatting

代码是:

 <form id="Data" runat="server" class="p-3 mb-2 bg-primary text-dark">
     <div class="form-group col">
        <label for="Countries" class="control-label">Email address</label>
            <asp:DropDownList name="Countries" ID="Countries" runat="server" AppendDataBoundItems="true" OnSelectedIndexChanged="Countries_Selected">
            <asp:ListItem Text="<Seleccione país>" Value="0" />
            </asp:DropDownList>
     </div>
     <div class="form-group col">
        <label for="DateIn" class="control-label">Email address</label>
            <asp:Textbox runat="server" TextMode="Date" name="DateIn" ID="DateIn" Text="Seleccione Fecha Devolucion">
            </asp:Textbox>
     </div>

     <div class="form-group col">
        <label for="DateOut" class="control-label">Email address</label>
            <asp:Textbox runat="server" TextMode="Date" name="DateOut" ID="DateOut" Text="Seleccione Fecha Retiro">
            </asp:Textbox>
     </div>

     <div class="form-group col">
        <label for="smth" class="control-label">Email address</label>
            <asp:DropDownList name="smth" ID="smth" runat="server" AppendDataBoundItems="true" OnSelectedIndexChanged="Countries_Selected">
                <asp:ListItem Text="<Seleccione país>" Value="0" />
            </asp:DropDownList>
     </div>

    </form>

目前我的网页显示如下:

Current style

2 个答案:

答案 0 :(得分:1)

您可以使用display: flex来获取布局。您需要进行更多调整才能获得与样式相匹配的输入。

我制作了两个辅助课程:columnscol

columns是一个display: flex的容器div。 col是div中flex: 1的每一列,这意味着它们将在容器内均匀分布。

&#13;
&#13;
form {
  width: 400px;
  background: #278339;
  color: #FFF;
  padding: 20px;
}

input,
select {
  width: 100%;
  margin-bottom: 10px;
}

.columns {
  display: flex;
}

.col {
  flex: 1;
  margin-right: 15px;
}
&#13;
<form id="Data" runat="server" class="p-3 mb-2 bg-primary text-dark">

  <div class="columns">

    <div class="col">

      <div class="form-group col-xs-4 col-md-4">
        <label for="DateIn" class="control-label">Fecha y Horario regreso</label>
        <input runat="server" TextMode="Date" name="DateIn" ID="DateIn" Text="Seleccione Fecha Devolucion">
        </input>
      </div>

      <div class="columns">

        <div class="col">
          <div class="form-group col-xs-4 col-md-4">
            <select name="Countries" ID="Countries" runat="server" AppendDataBoundItems="true" OnSelectedIndexChanged="Countries_Selected">
              <option Text="<Seleccione país>" Value="0" />
            </select>
          </div>
        </div>

        <div class="col">

          <div class="form-group col-xs-4 col-md-4">
            <select name="Countries" ID="Countries" runat="server" AppendDataBoundItems="true" OnSelectedIndexChanged="Countries_Selected">
              <option Text="<Seleccione país>" Value="0" />
            </select>
          </div>
        </div>
      </div>

    </div>


    <div class="col">
      <div class="form-group col-xs-4 col-md-4">
        <label for="Countries" class="control-label">Categorias:</label>
        <select name="Countries" ID="Countries" runat="server" AppendDataBoundItems="true" OnSelectedIndexChanged="Countries_Selected">
          <option Text="<Seleccione país>" Value="0" />
        </select>
      </div>
    </div>

  </div>


</form>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

使用两个rows,一个包含两个col-6,另一个包含两个col-3。我只使用了一个内联css样式。如果表单位于具有相同大小的另一个元素内,则不需要这样做。否则,将其更改为通过设计的任何数字。

    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet" />
    <form class="bg-success p-4 text-white mx-auto" style="width:500px">
      <div class="row">
        <div class="col-6 d-flex flex-column">
          <label for="DateIn">Fecha y Horario regreso</label>
          <input class="form-control" />
        </div>
        <div class="col-6 d-flex flex-column">
          <label for="Countries"> Categorias:</label>
          <select class="form-control">
            <option value="">one</option>
            <option value="">two</option>
            <option value="">three</option>
          </select>
        </div>
      </div>
      <div class="row mt-4">
        <div class="col-3">
          <select class="form-control">
            <option value="">one</option>
            <option value="">two</option>
            <option value="">three</option>
          </select>
        </div>
        <div class="col-3">
          <select class="form-control">
            <option value="">one</option>
            <option value="">two</option>
            <option value="">three</option>
          </select>
        </div>
      </div>
    </form>

更新

请按照以下步骤操作

  1. 形成一排
  2. col-6代表两个第一列
  3. col中断以强制将最后两列添加到新行
  4. col-3代表最后一次columns
  5. <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet" />
    <form class="row bg-success p-4 text-white mx-auto" style="width: 500px;">
      <div class="col-6 d-flex flex-column">
        <label for="DateIn">Fecha y Horario regreso</label>
        <input class="form-control radius-0">
      </div>
      <div class="col-6 d-flex flex-column">
        <label for="Countries"> Categorias:</label>
        <select class="form-control radius-0">
          <option value="">one</option>
          <option value="">two</option>
          <option value="">three</option>
        </select>
      </div>
      <!-- Force next columns to break to new line at md breakpoint and up -->
      <div class="w-100 d-none d-md-block my-3"></div>
      <div class="col-3">
        <select class="form-control radius-0">
          <option value="">one</option>
          <option value="">two</option>
          <option value="">three</option>
        </select>
      </div>
      <div class="col-3">
        <select class="form-control radius-0">
          <option value="">one</option>
          <option value="">two</option>
          <option value="">three</option>
        </select>
      </div>
    </form>

    检查此codepen

    如您所见,表单元素比img中的元素更曲线。如果您使用SCSS更改半径。否则,用css更改它。