简体   繁体   English

如何在下面放置元素

[英]How to place elements beneath

I am trying to make a little website and have two inputs.我正在尝试制作一个小网站并有两个输入。 The problem: One is on the right of the other, but I want to have it beneath.问题:一个在另一个的右边,但我想把它放在下面。 This is a very simple question, though I did not find a good answer.这是一个非常简单的问题,虽然我没有找到好的答案。

 <form> <h2>Login</h2> <input type="text" placeholder="Username" id="username"> <input left="40px" type="text" placeholder="Password" id="password"> <input type="submit" value="Login now"> </form>

Try to add some css class, playing with flex :尝试添加一些 css class,玩flex

.myForm {
  display: flex;
  flex-direction: column;
}

<form class="myForm">
    <h2>Login</h2>
    <input type="text" placeholder="Username" id="username">
    <input left="40px" type="text" placeholder="Password" id="password">
    <input type="submit" value="Login now">
</form>

You can make them display as block to have them beneath each other just add您可以使它们显示为块,使它们彼此下方,只需添加

input {
    display: block;
}

to your css file到您的 css 文件

 input { display: block; margin: 5px; }
 <form> <h2>Login</h2> <input type="text" placeholder="Username" id="username"> <input left="40px" type="text" placeholder="Password" id="password"> <input type="submit" value="Login now"> </form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM