是Web开发的新手,我尝试进行良好的登录。我无法正确确定元素的位置,因此不得不使用“ background-attachment:fixed!important;”。
不使用background-attachment: fixed !important;
还有其他方法可以达到相同的结果{下面给出的图片}>
这里是HTML {index.html}
<!DOCTYPE html> <html lang="en" dir="ltr"></html> <head> <meta charset="utf-8"> <title>Animated Login Form</title> <link rel="stylesheet" href="style.css"> </head> <body > <form class="box" action="index.html" method="POST"> <h1>Login</h1> <input type="text" name="" placeholder="Username"> <input type="password" name ="" placeholder="password"> <input type="submit" name="" value="Login"> </form> </body>
这里是CSS {style.css}
body{ margin:0; padding: 0; font-family: sans-serif; height: 100%; background: linear-gradient( red,green ); background-attachment: fixed !important; } .box { width: 300px; padding: 40px; position: absolute; top:50%; left:50%; transform: translate(-50%,-50%); background: #191919; text-align: center; } .box h1{ color: white; text-transform: uppercase; font-weight: 500; } .box input[type ="text"], .box input[type = "password"] { border: 0; background: none; display: block; margin: 20px auto; text-align: center; border: 2px solid #3498db; padding: 14px 10px; width: 200px; outline: none; color: white; border-radius: 24px; transition: 0.25s; } .box input[type ="text"]:focus, .box input[type = "password"]:focus{ width: 280px; border-color: #2ecc71; } .box input[type = "submit"]{ border: 0; background: none; display: block; margin: 20px auto; text-align: center; border: 2px solid #3498db; padding: 14px 40px; width: 200px; outline: none; color: white; border-radius: 24px; transition: 0.25s; cursor: pointer; } .box input[type= "submit"]:hover{ background: #2ecc71; }
我期望的结果
为了解决这个简单的问题,我花了很多时间在Google上搜索,但变得更加困惑,因此我希望对此有一些经验的人的建议,作为初学者,可以做和不做。
{对于Ans,如果您能放置整个代码并解释为什么选择特定的样式以及它如何解决一般问题,我将不胜感激(我读到使用“ background-attachment:fixed!important;”可能会导致麻烦)}谢谢。
是Web开发的新手,我尝试进行良好的登录。我无法正确确定元素的位置,因此不得不使用“背景附件:固定的!重要的”。还有其他...
您可以使用JavaScript设置背景高度等于您的滚动。