How to right-align form input boxes?

前端 未结 8 787
野的像风
野的像风 2021-01-01 08:53

I have a seemingly easy problem to solve, but am struggling. How do I get these two inputs to align to the right of the form, without using the BR element ?

         


        
8条回答
  •  猫巷女王i
    2021-01-01 08:56

    You can use floating to the right and clear them.

    form {
      overflow: hidden;
    }
    input {
      float: right;
      clear: both;
    }

    You can also set a right-to-left direction to the parent and restore the default left-to-right on the inputs. With display: block you can force them to be on different lines.

    form {
      direction: rtl;
    }
    input {
      display: block;
      direction: ltr;
    }

    Or the modern way, flexbox layout

    form {
      display: flex;
      flex-direction: column;
      align-items: flex-end;
    }

提交回复
热议问题