中心A表单HTML CSS

csga3l58  于 2023-11-15  发布在  其他
关注(0)|答案(5)|浏览(144)

你好,我有一个登录页面的表单居中的问题.我不擅长CSS,它已经有一段时间,因为我已经玩过HTML.我想做的是,中心的输入框和对齐的输入字段顶部的文字左,以及有一个图像居中,以及,就像在图片中。我已经尝试添加不同的div id和标签的形式,但我似乎不能弄清楚css的一部分。我感谢任何帮助,对不起,如果CSS是草率的。


的数据

  1. body {
  2. background-color:lightgray;
  3. font-family:Verdana, Arial, Helvetica, sans-serif;
  4. }
  5. h1 {
  6. color: black;
  7. }
  8. p {
  9. color: black;
  10. }
  11. html {
  12. text-alight: center;
  13. }
  14. #login {
  15. text-align:center;
  16. }
  17. input[type=text], input[type=date], input[type=password] {
  18. width: 30%;
  19. height: 50px;
  20. padding: 12px 20px;
  21. margin: 8px 0;
  22. box-sizing: border-box;
  23. }
  24. input[type=submit] {
  25. width: 30%;
  26. height: 50px;
  27. background-color: #4CAF50;
  28. border: none;
  29. color: white;
  30. padding: 16px 32px;
  31. text-decoration: none;
  32. margin: 4px 2px;
  33. cursor: pointer;
  34. }
  35. #service_type, #series, #speaker, #users {
  36. width: 30%;
  37. height: 50px;
  38. }
  39. @media only screen and (max-device-width: 1024px){
  40. input[type=text], input[type=date], input[type=password] {
  41. width: 100%;
  42. height: 50px;
  43. padding: 12px 20px;
  44. margin: 8px 0;
  45. box-sizing: border-box;
  46. }
  47. input[type=submit] {
  48. width: 100%;
  49. height: 50px;
  50. background-color: #4CAF50;
  51. border: none;
  52. color: white;
  53. padding: 16px 32px;
  54. text-decoration: none;
  55. margin: 4px 2px;
  56. cursor: pointer;
  57. }
  58. #service_type, #series, #speaker, #users{
  59. width: 100%;
  60. height: 50px;
  61. }
  62. #keypad_users{
  63. width: 345px;
  64. height: 50px;
  65. vertical-align:middle;
  66. text-align:center;
  67. border:1px solid #000000;
  68. font-size:30px;
  69. font-weight:bold;
  70. }
  71. #keypad {margin:auto; margin-top:10px;}
  72. #keypad tr td {
  73. vertical-align:middle;
  74. text-align:center;
  75. border:1px solid #000000;
  76. font-size:18px;
  77. font-weight:bold;
  78. width:100px;
  79. height:80px;
  80. cursor:pointer;
  81. background-color:#666666;
  82. color:#CCCCCC;
  83. }
  84. #keypad tr td:hover {
  85. background-color:#999999;
  86. color:#FFFF00;
  87. }
  88. #display {
  89. text-align:center;
  90. width:345px;
  91. margin:10px auto auto auto;
  92. background-color:#000000;
  93. color:#00FF00;
  94. font-size:48px;
  95. border:1px solid #999999;
  96. }
  97. #message {
  98. text-align:center;
  99. color:#009900;
  100. font-size:18px;
  101. font-weight:bold;
  102. display:none;
  103. }
  104. }

个字符

oipij1gg

oipij1gg1#

我已经为你做了一个JSfiddle here (click me please),它类似于你添加的图片。
按照要求,不要使用第三方,就像我在这里添加的代码:
HTML

  1. <div id="login">
  2. <form action = "login.php" id="login" method ="POST">
  3. <div class="picture">
  4. </div>
  5. <p>Username</p>
  6. <input type="text" name="username" id="username" required /><br /><br />
  7. <p>Password</p>
  8. <input type ="password" name="password" id="password" required /><br /><br />
  9. <input type="submit" name="submit" value="Log in">
  10. </form>
  11. </div>

字符串
CSS

  1. body
  2. {
  3. background-color:lightgray;
  4. font-family:Verdana, Arial, Helvetica, sans-serif;
  5. }
  6. #login
  7. {
  8. text-align:center;
  9. width: 50%;
  10. margin: 0 auto;
  11. }
  12. .picture
  13. {
  14. width:100px;
  15. height: 100px;
  16. border-radius: 100px;
  17. background-color:red;
  18. margin: 0 auto;
  19. }
  20. #login p
  21. {
  22. float: left;
  23. }
  24. input[type=text], input[type=date], input[type=password] {
  25. width: 100%;
  26. height: 50px;
  27. padding: 12px 20px;
  28. margin: 8px 0;
  29. box-sizing: border-box;
  30. }
  31. input[type=submit] {
  32. width: 100%;
  33. height: 50px;
  34. background-color: #4CAF50;
  35. border: none;
  36. color: white;
  37. padding: 16px 32px;
  38. text-decoration: none;
  39. margin: 4px 2px;
  40. cursor: pointer;
  41. }

**编辑:**新提琴在这里:https://jsfiddle.net/gay1ufa1/2/

展开查看全部
cigdeys3

cigdeys32#

我已经改进了你的HTML。所有的表单输入都应该有一个相关的label元素。也不要使用br作为间距,而是使用padding/margin。
此外,使用重复的id,id必须是唯一的页面。

  1. #login_container /*This is Our base container for the login "control" */
  2. {
  3. width:30%; /*Define the width of the control*/
  4. margin:auto; /*This Provide the horizontal centering of the control*/
  5. padding:120px 10px 10px 10px; /*Add some padding, the first number is the top and provides room for the image*/
  6. background-image:url(" http://fillmurray.com/100/100"); /*Add our background image, thanks Bill Murray*/
  7. background-position:center 10px; /*Position our image, first is Horizontal alignment, second is top*/
  8. background-repeat:no-repeat; /*One Bil Murray is more than enough*/
  9. background-color: #F0F0F0; /*Base Background image*/
  10. }
  11. #login_container label
  12. {
  13. display:block; /*Label will now take up a whole line*/
  14. margin-bottom:.25em; /*Give it some room underneath*/
  15. }
  16. #login_container input[type="text"], #login_container input[type="password"], #login_container input[type="submit"]
  17. {
  18. width:100%; /*Form controls now take 100% width of the container*/
  19. margin-bottom:0.5em;
  20. }

个字符

展开查看全部
7gyucuyw

7gyucuyw3#

你的代码中有一个问题是你使用了两次ID“login“,这是绝对不能做的。我整理了一个codepen,你可以在这里找到:
http://codepen.io/anon/pen/dNWQgp
我基本上做了什么(除了添加一个代表图片的div):我将以下CSS分配给整个表单和图像的 Package 器DIV。它使用flexbox来集中内容。另外,我将form设置(40%)分配给form元素。

  1. .wrapper {
  2. width: 100%;
  3. height: 100%;
  4. display: flex;
  5. flex-direction: column;
  6. align-items: center;
  7. justify-content: center;
  8. }

字符串

8tntrjer

8tntrjer4#

要使div居中,请将margin-leftmargin-right设置为auto,并为其分配固定的width。在您的情况下,这将用于#login

lg40wkob

lg40wkob5#

最小的跳转开始模板,使用CSS flex:

  1. body {background:darkblue;margin:0;min-height:100vh;display:flex;align-items:center;justify-content:space-around;font-size:large}
  2. #container {width:30%;margin:auto;padding:2em;background-color:#F0F0F0;border-radius: 0.5em}
  3. #container input {margin:0.5em 0 1em 0;height: 2em;padding: 0.5em;width:calc(100% - 1.5em);font-weight:bold}
  4. #container input[type="submit"] {cursor:pointer;font-size:larger;margin:0.5em 0 0 0;padding:0.2em;width:100%}

个字符
在CSS中更进一步,同时保持它相当小。emoji图标是Unicode字符,取自Unicode 15.1 https://www.unicode.org/emoji/charts-15.1/emoji-style.txt

  1. body {background:darkblue;margin:0;min-height:100vh;display:flex;align-items:center;justify-content:space-around;font-size:large}
  2. .logo {
  3. height: 7em;
  4. max-height: 7em;
  5. max-width: 7em;
  6. background: #272b2d;
  7. background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='0.8em' font-size='100'>🧔🏻‍♂️</text></svg>");
  8. background-size: cover;
  9. border-radius: 7em;
  10. border: 0.5em deepskyblue solid;
  11. transition: transform .7s ease-in-out;
  12. margin: 0 auto 1em auto
  13. }
  14. .logo:hover {transform: rotate(360deg);cursor:crosshair}
  15. #container {width:12em;margin:auto;padding:2em;background-color:#F0F0F0;border-radius: 0.5em;min-width:12em;max-width:12em;transition: all 0.5s ease-in}
  16. #container:hover {box-shadow: rgba(255, 255, 255, 0.3) 0px 0px 50px}
  17. #container input {margin:0.5em 0 1em 0;height: 2em;padding: 0.5em;width:calc(100% - 1.5em);font-weight: bold}
  18. #container input[type="submit"] {cursor:pointer;font-size:larger;margin:0.5em 0 0 0;padding:0.2em;width:100%}
  1. <!DOCTYPE html>
  2. <meta charset=utf-8>
  3. <title>DB</title>
  4. <body>
  5. <div id="container">
  6. <div class="logo"></div>
  7. <form action = "login.php" id="login" method ="POST">
  8. <label for="username">Username </label>
  9. <input type="text" name="username" id="username" required />
  10. <label for="password">Password</label>
  11. <input type ="password" name="password" id="password" required />
  12. <input type="submit" name="submit" value="Log in">
  13. <br><br>
  14. <a href="#">Register account</a>
  15. </form>
  16. </div>
  17. </body></html>


的数据

展开查看全部

相关问题