简体   繁体   English

引导中文本框和按钮的CSS对齐问题

[英]CSS alignment issue of textbox and button in bootstrap

I'm newbie in Angular and trying to develop my first application but stuck in alignment using bootstrap classes. 我是Angular的新手,正在尝试开发我的第一个应用程序,但使用引导程序类无法对齐。

Here is my Code: 这是我的代码:

 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> <div class="row"> <div class="form-group col-md-4"> <label>Client</label> <Select class="form-control"> <option>Client 1</option> <option>Client 2</option> <option>Client 3</option> <option>Client 4</option> <option>Client 5</option> <option>Client 6</option> </Select> </div> <div class="form-group col-md-4"> <button type=submit class="btn btn-sm btn-success"><i class="fa fa-dot-circle-o"></i> Add</button> </div> <div class="form-group col-md-4"> <button type="submit" class="btn btn-sm btn-info pull-right" vertical-align="bottom"><i class="fa fa-dot-circle-o"></i> Get Data</button> </div> </div> 

and here the output of this code 这是此代码的输出

在此处输入图片说明

Problem is that all these inputs are top-aligned but I want client dropdown and both buttons to be bottom aligned. 问题是所有这些输入都在顶部对齐,但是我希望客户端下拉菜单和两个按钮都在底部对齐。

I tried input-group-btn class but that didn't work for me. 我尝试了input-group-btn类,但是对我来说不起作用。 Even here on StackOverflow, I found solutions only about right-alignment. 即使在StackOverflow上,我也只找到关于右对齐的解决方案。

try this code, i am not sure but <label >&nbsp;</label> this should work to align them in one line. 试试这个代码,我不确定,但是<label >&nbsp;</label>应该可以使它们对齐。

update this css 更新此CSS

<style>    
   label {
        width: 100%;
    }
</style>

 label { width: 100%; } 
 <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> <div class="row"> <div class="form-group col-md-4"> <label >Client</label> <Select class="form-control" > <option>Client 1</option> <option>Client 2</option> <option>Client 3</option> <option>Client 4</option> <option>Client 5</option> <option>Client 6</option> </Select> </div> <div class="form-group col-md-4"> <label >&nbsp;</label> <button type=submit class="btn btn-sm btn-success"><i class="fa fa-dot-circle-o"></i> Add </button> </div> <div class="form-group col-md-4"> <label >&nbsp;</label> <button type="submit" class="btn btn-sm btn-info pull-right" vertical-align="bottom"><i class="fa fa-dot-circle-o"></i> Get Data </button> </div> </div> 

you can also apply margin-top css style to div which contains those buttons. 您还可以将margin-top css样式应用于包含这些按钮的div。

<style>    
   .margin_top_25 {
       margin-top:25px;
    }
</style>

<div class="row">
  <div class="form-group col-md-4">
    <label >Client</label>
    <Select class="form-control" >
      <option>Client 1</option>
      <option>Client 2</option>
      <option>Client 3</option>
      <option>Client 4</option>
      <option>Client 5</option>
      <option>Client 6</option>
    </Select>
  </div>
  <div class="form-group col-md-4 margin_top_25">
    <button type=submit class="btn btn-sm btn-success"><i class="fa fa-dot-circle-o"></i> Add </button>
  </div>
  <div class="form-group col-md-4 margin_top_25">
    <button type="submit" class="btn btn-sm btn-info pull-right" vertical-align="bottom"><i class="fa fa-dot-circle-o"></i>  Get Data </button> 
  </div>
</div>

Create a table instead and vertical align your tds : 而是创建一个表并垂直对齐您的tds:

<table>
  <tr class="row">
   <td class="col-md-4"><label >Client</label>
    <Select class="form-control" >
      <option>Client 1</option>
      <option>Client 2</option>
      <option>Client 3</option>
      <option>Client 4</option>
      <option>Client 5</option>
      <option>Client 6</option>
    </Select>
   </td>
   <td class="col-md-4">
     <button type=submit class="btn btn-sm btn-success"><i class="fa      fa-dot-circle-o"></i> Add </button>
   </td>
   <td class="col-md-4">
     <button type="submit" class="btn btn-sm btn-info pull-right"  vertical-align="bottom"><i class="fa fa-dot-circle-o"></i>  Get Data </button> 
   </td>
</tr>
</table>

And then : 接着 :

td{
 vertical-align:bottom
}

Note : This is not an absolute solution.Tweak your css and html to get the exact layout , but this should align your elements as desired. 注意:这不是绝对的解决方案,请调整css和html以获取确切的布局,但这应根据需要对齐元素。

You can do this alignment by using flex-box. 您可以使用flex-box进行对齐。 I have attached a plunker I created. 我已经附上了我创建的一个pl子。 If you have any questions then please let me know. 如果您有任何疑问,请告诉我。

Plunkr Plunkr

.form-group {
  width: 50%;
  margin: 0 auto;
  margin-top: 10%;
}

.client-label {
  margin-left: 40%;
  font-size: 3vw;
  text-transform: uppercase;
  color: teal;
}

.add-button {
  width: 100px;
}

.data-button {
  width: 100px;
}

div.form-group {
  width: 50%;
  margin-left: 25%;
}

.buttons {
  margin: 0;
  padding: 0;
  border: 0;
  display: flex;
  justify-content: space-between;
}

Thanks! 谢谢!

div inside div resolved my problem.. here is my code div inside div解决了我的问题..这是我的代码

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

 <div class="row">
     <div class="col-md-12">
          <label >Client</label>
          <div class="row">
               <div class="form-group col-md-4">
                     <Select class="form-control" >
                           <option>Client 1</option>
                           <option>Client 2</option>
                           <option>Client 3</option>
                           <option>Client 4</option>
                           <option>Client 5</option>
                           <option>Client 6</option>
                          </Select>
                         </div>
                         <div class="form-group col-md-4">
                             <button type=submit class="btn btn-sm btn-success"><i class="fa fa-dot-circle-o"></i> Add </button>
                         </div>
                         <div class="form-group col-md-4">
                              <button type="submit" class="btn btn-sm btn-info pull-right" vertical-align="bottom"><i class="fa fa-dot-circle-o"></i>  Get Data </button> 
                          </div>
                      </div>

              </div>
            </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM