使用css / flex以不同方式对齐项目

时间:2016-06-04 23:13:29

标签: html css css3 flexbox

我正在制作一张表格。 我想让<h>标签在文本字段的开头对齐,并使文本字段位于中心。但是,文本字段和<h>标记现在都在中心对齐。如何按照我的意图调整它们?

    <div class="vertical-offset--small inner-contact" style="display:flex; flex-direction: column; align-items: center; justify-content: center">



            <h5 style="display:inline">* First Name:</h5>
            <input type="text" class="form-control textfield-control textfield" ng-class id="first_name" name="first_name" ng-model="formData.first_name" style="width: 90%" ng-blur="realtimeSave()" required>
            <br>

            <h5>* Last Name:</h5>
            <input type="text" class="form-control textfield-control textfield" ng-class id="last_name" name="last_name" ng-model="formData.last_name" style="width: 90%" ng-blur="realtimeSave()" required>
            <br>

            <h5>* Email:</h5>
            <input type="text" class="form-control textfield-control textfield" ng-class id="email" name="email" ng-model="formData.email" style="width: 90%" ng-blur="realtimeSave()" required>
            <br>

            <h5>* My Question:</h5>
            <textarea id="question" name="question" ng-model="formData.question" ng-blur="realtimeSave()" style="width: 90%; height: 150px;" class="form-control textfield-control textfield" required>
            </textarea>
            <br>
            <br>
            <br>

            <div style="text-align:center">
                <button ng-click="sendEmail($event)" class="button button-form-success button--primary">
                    Submit
                </button>
            </div>
    </div>

在div上我打电话跟风:

 style="display:flex; flex-direction: column; align-items: center; justify-content: center"

1 个答案:

答案 0 :(得分:3)

在每个tags上添加以下样式:

h5.tag {
  align-self: flex-start;
}

请参阅此代码段中的示例:

&#13;
&#13;
h5.tag {
  align-self: flex-start;
}
&#13;
<div class="vertical-offset--small inner-contact" style="display:flex; flex-direction: column; align-items: center; justify-content: center">

  <input type="hidden" name="_subject" value="Submission from FoundVisa!" />

  <h5 style="display:inline">* First Name:</h5>
  <input type="text" class="form-control textfield-control textfield" ng-class id="first_name" name="first_name" ng-model="formData.first_name" style="width: 90%" ng-blur="realtimeSave()" required>
  <br>

  <h5>* Last Name:</h5>
  <input type="text" class="form-control textfield-control textfield" ng-class id="last_name" name="last_name" ng-model="formData.last_name" style="width: 90%" ng-blur="realtimeSave()" required>
  <br>

  <h5>* Email:</h5>
  <input type="text" class="form-control textfield-control textfield" ng-class id="email" name="email" ng-model="formData.email" style="width: 90%" ng-blur="realtimeSave()" required>
  <br>

  <h5>* My Question:</h5>
  <textarea id="question" name="question" ng-model="formData.question" ng-blur="realtimeSave()" style="width: 90%; height: 150px;" class="form-control textfield-control textfield" required>


    <div style="text-align:center">
      <button ng-click="sendEmail($event)" class="button button-form-success button--primary">
        Submit
      </button>
    </div>
</div>
&#13;
&#13;
&#13;