如何让'first-name'项和它的表格在同一行

How to make the 'first-name' item and its form in the same row

我有一个 "My Account" 表单,我希望 "First name" 与文本区域位于同一行。 我尝试了一些方法,但其中 none 有效。

这是我当前的代码:

.personal_details {
    max-width: 503px;
    float: none;
    margin: 0 auto;
    padding: 40px;
    border-radius: 5px;
}

.form-control {
  display: block;
    width: 100%;
    height: calc(1.5em + .75rem + 2px);
    padding: .375rem .75rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #495057;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid #ced4da;
    border-radius: .25rem;
    transition: border-color .15s ease-in-out,box-     shadow .15s ease-in-out;
}
<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="personal_details">
  <div class="form-group">
      <label for="firstName">First name</label>
      <input type="text" class="form-control" name="firstName" />
  </div>
  <div class="form-group">
      <label for="lastName">Last name</label>
      <input type="text" class="form-control" name="lastName" />
  </div>
</div

您可以使用 Css 轻松完成此操作。希望对你有帮助。

input {
    display: block !important;
    width: auto !important;
}

label {
    float: left;
    line-height: 3em;
    margin-right: 15px;
}

谢谢

[

.personal_details {
    max-width: 503px;
    float: none;
    margin: 0 auto;
    padding: 40px;
    border-radius: 5px;
}

.form-control {
  display: block;
    width: 100%;
    height: calc(1.5em + .75rem + 2px);
    padding: .375rem .75rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #495057;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid #ced4da;
    border-radius: .25rem;
    transition: border-color .15s ease-in-out,box-     shadow .15s ease-in-out;
    margin-left: 30px;

}
<!DOCTYPE html>
<html lang="en" dir="ltr">
      <head>
            <meta charset="utf-8">
            <title>Testing</title>
            <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">
            <link rel="stylesheet" href="newTest1.css">
      </head>
      <body>
            <div class="personal_details">
                  <div class="form-group">
                        <table>
                              <tr>
                                    <td><label for="firstName">First name</label></td>
                                    <td><input type="text" class="form-control" name="firstName" /></td>
                              </tr>
                        </table>
                  </div>

                  <div class="form-group">
                        <table>
                              <tr>
                                    <td><label for="lastName">Last name</label></td>
                                    <td><input type="text" class="form-control" name="lastName" /></td>
                              </tr>
                        </table>
                  </div>
            </div>
      </body>
</html>

]1

在这种情况下,我更喜欢使用 table 来使我的元素保持在正确的位置并正确对齐。