简体   繁体   English

使用CSS垂直样式列表元素

[英]Styling list elements vertically using css

I have the following html5 and css, where I have a username & password type input. 我有以下html5和CSS,其中有用户名和密码类型输入。 I would like to have the li elements to be displayed vertically, instead of horizontally, and have the two labels align vertically, while the two input text boxes also align vertically. 我想让li元素垂直显示,而不是水平显示,并使两个标签垂直对齐,而两个输入文本框也垂直对齐。

Code: 码:

 .loginform li { background-color: purple; display:block; float:left; width:300px; heigh:150px; padding: 5px; } 
 <section class="loginform cf"> <form name="login" action="index_submit" method="get" accept-charset="utf-8"> <ul> <li> <label for="usermail">Email</label> <input type="email" name="usermail" placeholder="yourname@email.com" required> </li> <li><label for="password">Password</label> <input type="password" name="password" placeholder="password" required> </li> <li> <input type="submit" value="Login"> </li 

I think you want something like this, hope it will helps you. 我认为您想要这样的东西,希望对您有所帮助。

and check your height spell it was heigh 检查你的身高拼写是heigh

 .loginform li { background-color: purple; display:block; /*float:left;*/ width:300px; /*height:150px;*/ padding: 5px; box-sizing:border-box } .loginform li label, .loginform li input{ display:block; width:100%; box-sizing:border-box } 
 <section class="loginform cf"> <form name="login" action="index_submit" method="get" accept-charset="utf-8"> <ul> <li> <label for="usermail">Email</label> <input type="email" name="usermail" placeholder="yourname@email.com" required> </li> <li><label for="password">Password</label> <input type="password" name="password" placeholder="password" required> </li> <li> <input type="submit" value="Login"> </li 

Have your list items clear everything to the left, so that they stack up underneath one-another. 让您的清单项目清除左侧的所有内容,以便它们彼此堆叠。

Then give your labels a width and they will line up alone with your <input> elements: 然后给标签加上宽度,它们将与您的<input>元素单独对齐:

 .loginform li { background-color: purple; display:block; float:left; clear: left; width:300px; height:150px; padding: 5px; } .loginform li label{ display: inline-block; width: 30%; } 
 <section class="loginform cf"> <form name="login" action="index_submit" method="get" accept-charset="utf-8"> <ul> <li> <label for="usermail">Email</label> <input type="email" name="usermail" placeholder="yourname@email.com" required> </li> <li><label for="password">Password</label> <input type="password" name="password" placeholder="password" required> </li> <li> <input type="submit" value="Login"> </li> </ul> </form> 

FYI: height , not heigh 仅供参考: 身高 ,不高

Did you mean like this? 你是这个意思吗

https://jsfiddle.net/ytaknyp9/1/ https://jsfiddle.net/ytaknyp9/1/

Just put 刚放

<br />

between your label and input. 在标签和输入之间。

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

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