如何在输入密码箱中输入忘记链接?

时间:2014-08-28 14:01:37

标签: html css

我想把链接"忘记"像这样:

enter image description here

但我无法做到这一点:

我尝试更改位置:绝对在css中链接

像这样的HTML:

<div>
                                <input id="txtPassword" type="password" class="textfield password" placeholder="Password" />
                                 <a id="lnkforget" class="hyperlink" style="float: right; margin-right: 5px;">Forgot</a>
                            </div>

我的演示:http://jsfiddle.net/d0joydmn/

3 个答案:

答案 0 :(得分:2)

您可以使用:

<div style="position: relative;">
    <input id="txtPassword" type="password" class="textfield password" placeholder="Password" />
    <a id="lnkforget" class="hyperlink" style="float: right; margin-right: 5px;position: absolute;top: 7px;right: 0px;">Forgot</a>
</div>

fiddle

在您的容器div position:relative#lnkforget集合position:absoluteright: 0px

在@quantumwannabe评论之后:

  

你可以添加padding-right:55px和box-sizing:border-box到   输入元素

答案 1 :(得分:1)

我知道它有点老了,但也许有人需要这样做..我已经用这样的bootstrap 4完成了这个:

<div class="input-group mb-3">
    <input type="password" class="form-control border-right-style-none focus-none" placeholder="Password">
    <span class="input-group-addon focus-none" style="background: white; font-size: 80%;">
      <a class="small" href="/password/forgot">Forgot?</a>
    </span>
  </div>

和我用过的css类:

.border-right-style-none {
     border-right-style: none;
}

.border-left-style-none {
    border-left-style: none;
}

.focus-none {
    &:focus {
        -webkit-box-shadow: none !important;
        box-shadow: none !important;
        outline: none !important;
        border-color: rgba(0, 0, 0, 0.15) !important;
    }
}

答案 2 :(得分:0)

Demo:

[id=txtPassword]{
    width:200px;
    height:32px;
    border:2px solid red;
    border-radius:4px;
}

[id=txtPassword] +  [id=lnkforget]{
    margin-left:-72px;
    padding:2px 10px;
    background:red;
    transition:margin-left 300ms ease;
    border-radius:4px;
}

[id=txtPassword]:focus +  [id=lnkforget]{
   margin-left:12px; 
}

标记:

<input id=txtPassword type=password class="textfield password" placeholder="Password" />
<a id=lnkforget class=hyperlink>Forgot</a>