css - 如何使用 css 对齐 html 页面中同一行的两个表单字段?

标签 css forms css-float styling border-box

我有这个 html 文本

<meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">


<div class="glossary-form"></div>

<div class="form-group" style="display:inline-block; width:48%;padding-right: 5%;">
  <label for="glossary_entry_input_1">Lemma IT</label>
  <input type="text" class="form-control" id="glossary_entry_input_1" placeholder="">              
</div>

<div class="form-group" style="display:inline-block; width:48%; padding-left: 5%;">
		<label for="glossary_entry_input_2">Lemma CH</label>
		<input type="text" class="form-control" id="glossary_entry_input_2" placeholder="">              
</div>

<div class="form-group">
                    <label for="glossary_entry_input_3">Acronimo IT</label>
                    <small id="inputHelp" class="form-text text-muted">Inserire una sigla (se esiste) del Lemma. Nel caso in cui il lemma sia una grandezza fisica, inserire la lettera o il simbolo che la identifica.</small>
                    <input type="text" class="form-control" id="glossary_entry_input_3" placeholder="">              
            </div>  

</div>

生成以下表单字段,如您所见,在一行上对齐

enter image description here

我想通过将第二个向右移动,将它们对称地显示到我的 html 页面的垂直轴上,如您所见

enter image description here

因此“引理 CH”框的左边距与“Acronimo IT”框之一对齐。 我必须如何更改我的代码才能获得第二张图片中显示的结果?

最佳答案

向右浮动不是正确的解决方案。试试这个。

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
  integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">


<div class="glossary-form"></div>
<div class="row">
  <div class="col-md-6">
    <div class="form-group">
      <label for="glossary_entry_input_1">Lemma IT</label>
      <input type="text" class="form-control" id="glossary_entry_input_1" placeholder="">
    </div>
  </div>
  <div class="col-md-6">
    <div class="form-group">
      <label for="glossary_entry_input_2">Lemma CH</label>
      <input type="text" class="form-control" id="glossary_entry_input_2" placeholder="">
    </div>
  </div>

</div>
<div class="row">
  <div class="col-md-12">
    <div class="form-group">
      <label for="glossary_entry_input_3">Acronimo IT</label>
      <small id="inputHelp" class="form-text text-muted">Inserire una sigla (se esiste) del Lemma. Nel caso in cui il
        lemma sia una grandezza fisica, inserire la lettera o il simbolo che la identifica.</small>
      <input type="text" class="form-control" id="glossary_entry_input_3" placeholder="">
    </div>

  </div>
</div>
</div>

关于css - 如何使用 css 对齐 html 页面中同一行的两个表单字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56986440/

相关文章:

c# - ASP.NET Web 控件在第一次回发后显示旧数据

javascript - Angular : checkbox on form does not become checked when value from API is returned until I submit the form

html - CSS 显示 : table-cell float causes extra space in the text

css - 集中 float 元素

javascript - 使用 jQuery 展开一个 Div

python - 在 HTML 中显示一个 python 文件,保留空格等

html - 设置元素的宽度严格等于它的文本内容

html - 在现场插入 Reverbnation Widget - 使用 CSS 放置它

python - django - int 参数必须是字符串或数字,而不是 'Tuple'

html - 溢出 :hidden includes float in container - why?