简体   繁体   English

如何在同一条线上对齐两个输入 class?

[英]how to align two input class on the same line?

I want to align two input classes next to each other with some space in between them like the following image.我想将两个相邻的输入类对齐,它们之间有一些空间,如下图所示。 enter image description here在此处输入图像描述

However, my current output is like this: enter image description here但是,我现在的 output 是这样的: enter image description here

The html code is html 代码为

<div class="form-group">
    <div class="row">
        <label  for="form-workphoneNumber" class="col-sm-4 col-xs-4 control-label">input</label>
        <div id="box" class="col-sm-8 col-xs-8">
            <input type="text" class="form-control" name="workphoneNumber" placeholder="enter">
            <input type="button" class="btn btn-success" value="add" onclick="add_textbox()">
        </div>
    </div>
</div>

Just add width and margin只需添加宽度和边距

style="margin-right:5px;width:80%;float:left"

 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"> <div class="form-group"> <div class="row"> <label for="form-workphoneNumber" class="col-sm-4 col-xs-4 control-label">input</label> <div id="box" class="col-sm-8 col-xs-8"> <input style="margin-right:5px;width:80%;float:left" type="text" class="form-control" name="workphoneNumber" placeholder="enter"> <input style="width:15%;float:left" type="button" class="btn btn-success" value="add" onclick="add_textbox()"> </div> </div> </div>

You can also use display: inline-block instead of float .您还可以使用display: inline-block代替float

 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"> <div class="form-group"> <div class="row"> <label for="form-workphoneNumber" class="col-sm-4 col-xs-4 control-label">input</label> <div id="box" class="col-sm-8 col-xs-8"> <input style="margin-right:5px;width:80%;display:inline-block;vertical-align:top" type="text" class="form-control" name="workphoneNumber" placeholder="enter"> <input style="width:15%;display:inline-block" type="button" class="btn btn-success" value="add" onclick="add_textbox()"> </div> </div> </div>

I suggest you to avloid inline styling and use bootstrap classes for good practices我建议您不要使用内联样式并使用引导类进行良好实践

input 输入

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

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