Search code examples
htmlcssscss-lint

CSS Is it possible to align a submit button with input fields?


Currently I get :

form 1

I am trying to align the button with the input fields to get displayed like that

( Note: I can add a margin-left: 40px to the button csss description, but I am not sure it's the best option ) :

form target

with the following template and scss

LoginPage.vue

<template>
  <div class="login-page">
    <h1 class="title">Login to existing account</h1>
    <form @submit.prevent="login()" class="form form--login grid">
      <div class="row">
        <label for="login__email">Email</label>
        <input type="text" id="login__email" class="input--block" v-model="email" />
      </div>
      <div class="row">
        <label for="login__password">Password</label>
        <input type="password" id="login__password" class="input--block" v-model="password" />
      </div><!-- /.row -->
      <div class="row">
        <button type="submit">Login</button>
      </div><!-- /.row -->
    </form>
  </div><!-- /.login-page -->
</template>

<style lang="scss" scoped>
  .login-page {
    form {
      .row {
        padding-top: 5px;
        label {
          display: inline-block;
          width: 140px;
          text-align: right;
        }
        input {
          display: inline-block;
          text-align: left;
        }
      }
    }
  }
</style>

Solution

  • If you don't want to give margin in the submit button. You can give a label for submit button.

    Check this:

      <div class="login-page">
        <h1 class="title">Login to existing account</h1>
        <form @submit.prevent="login()" class="form form--login grid">
          <div class="row">
            <label for="login__email">Email</label>
            <input type="text" id="login__email" class="input--block" v-model="email" />
          </div>
          <div class="row">
            <label for="login__password">Password</label>
            <input type="password" id="login__password" class="input--block" v-model="password" />
          </div><!-- /.row -->
          <div class="row">
            <label></label>
            <button type="submit">Login</button>
          </div><!-- /.row -->
        </form>
      </div><!-- /.login-page --></code>
    

    I only added there one new line: <label></label> in the row of submit button . That's why it can take a width like another fields.