html中input和relative,css – style =“position:absolute”和style =“position:relative”之间的差异...

绝对定位意味着元素完全脱离页面布局的正常流动。就页面上的其余元素而言,绝对定位的元素根本不存在。然后,使用左,右,顶部和底部属性,在您指定的位置单独绘制元素本身,排序在其他一切的“顶部”。

使用您使用这些属性指定的位置,元素然后放置在其最后一个祖先元素中的该位置,该元素具有除静态之外的任何位置属性(静态是定位元素在没有指定位置属性时使用),或者文档主体(浏览器视口)(如果不存在这样的祖先)。

例如,如果我有这样的代码:

… then< div>将位于距浏览器视口顶部20像素,距离左边缘20像素。

但是,如果我做了这样的事情:

…然后内部div将位于距离外部div的顶部20px,和从左边缘的20px相同,因为外部div不定位与position:static,因为我们明确设置为使用位置:相对。

相对定位,另一方面,就像没有定位,但左,右,顶部和底部属性“微调”元素的正常布局。页面上的其余元素仍然被布置,好像元素在正常的位置。

例如,如果我有这样的代码:

Span1

Span2

Span3

…然后所有三个< span>元素将彼此相邻而不重叠。

如果我将第二个< span>使用相对定位,如下:

Span1

Span2

Span3

…然后Span2会重叠Span1的右边5px。 Span1和Span3将位于与他们在第一个例子中完全相同的地方,在Span2的右侧和Span3的左侧之间留下5px的间隙。

希望澄清的东西有点。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是通过register.html来写login.html代码的示例代码: login.html ``` <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Login</title> <link rel="stylesheet" href="s1.css"> </head> <body> <div class="login-box"> <h2>Login</h2> <form> <div class="user-box"> <input type="email" name="email" required> <label>Email</label> </div> <div class="user-box"> <input type="password" name="password" required> <label>Password</label> </div> <a href="#"> <span></span> <span></span> <span></span> <span></span> Submit </a> <p class="signup-link">Don't have an account? <a href="register.html">Sign up</a></p> </form> </div> </body> </html> ``` 在以上代码,我们将用户名改为了邮箱,并且添加了“Don't have an account? Sign up”链接。 接着,这里是改进后的s1.css代码: s1.css ``` * { margin: 0; padding: 0; box-sizing: border-box; font-family: sans-serif; } body { background: #1e272e; } .login-box { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 350px; height: 500px; padding: 80px 40px; background: #fff; border-radius: 10px; } .login-box h2 { margin: 0 0 30px; padding: 0; color: #333; text-align: center; } .login-box .user-box { position: relative; } .login-box .user-box input { width: 100%; padding: 10px 0; font-size: 16px; color: #333; margin-bottom: 30px; border: none; border-bottom: 1px solid #777; outline: none; background: transparent; } .login-box .user-box label { position: absolute; top: 0; left: 0; padding: 10px 0; font-size: 16px; color: #777; pointer-events: none; transition: .5s; } .login-box .user-box input:focus ~ label, .login-box .user-box input:valid ~ label { top: -20px; left: 0; color: #333; font-size: 12px; } .login-box a { display: inline-block; background: #1e272e; color: #fff; text-transform: uppercase; font-size: 16px; text-align: center; padding: 14px 40px; margin-top: 50px; border-radius: 30px; overflow: hidden; position: relative; } .login-box a span { position: absolute; display: block; background: #fff; width: 20px; height: 20px; border-radius: 50%; animation: a 1s linear infinite; z-index: -1; } .login-box a span:nth-child(1) { left: -25%; top: -50%; animation-delay: 0ms; } .login-box a span:nth-child(2) { left: -25%; top: 150%; animation-delay: 500ms; } .login-box a span:nth-child(3) { right: -25%; top: -50%; animation-delay: 1000ms; } .login-box a span:nth-child(4) { right: -25%; top: 150%; animation-delay: 1500ms; } .login-box a:hover span { animation: none; } .signup-link { text-align: center; margin-top: 20px; } .signup-link a { color: #1e272e; font-weight: bold; text-decoration: none; } .signup-link a:hover { text-decoration: underline; } ``` 在以上代码,我们添加了一个“Don't have an account? Sign up”链接,并为其设置了样式。同时,我们将按钮的背景颜色与链接的文字颜色进行了调整,以提升整体的视觉效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值