移动输入文本框内的glyphicon

时间:2017-09-17 19:31:55

标签: javascript jquery html css glyphicons

我希望glyphicon-remove放在输入文本框的右端,这是我的代码 -

*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body{
  position: relative;
  background-color: rgba(0,0,0,0.9);
  height: 100vh;
}
.content{
  text-align: center;
  position: absolute;
  width: 100%;
  top: 50%;
  left: 50%;
  transform:translate(-50%,-50%);
}
.fill_text{
  width: 20%;
  height: 42px;
  background-color: #DDD;
  border-radius: 20px;
  font-size: 20px;
  padding: 10px;
  border: 5px solid #E35F14;
  margin: 10px auto;
  outline: 0;
  position: relative;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

  <div class="content">
  <input type="text" class="fill_text">
    <span class="glyphicon glyphicon-remove"></span>
  </input>
  </div>

我将输入文本框的位置设置为相对,我尝试将删除图标的位置设为绝对,但这不起作用。你能告诉我为什么那不起作用吗?

1 个答案:

答案 0 :(得分:2)

  

<input>元素中不允许使用任何元素。

添加此CSS

  .glyphicon-remove{
      position: absolute;
      top: 50%;
      right: 30px;
      z-index:10;
    }

*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body{
  position: relative;
  background-color: rgba(0,0,0,0.9);
  height: 100vh;
}
.content{
  text-align: center;
  position: absolute;
  width: 100%;
  top: 50%;
  left: 50%;
  transform:translate(-50%,-50%);
}
.fill_text{
  width: 20%;
  height: 42px;
  background-color: #DDD;
  border-radius: 20px;
  font-size: 20px;
  padding: 10px;
  border: 5px solid #E35F14;
  margin: 10px auto;
  outline: 0;
  position: relative;

  
}
.glyphicon-remove{
  position: absolute;
  top: 50%;
  right: 30px;
  z-index:10;
  cursor:pointer;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

  <div class="content">
  <input type="text" class="fill_text"/>
    <span class="glyphicon glyphicon-remove"></span>
  </div>