我想将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>





我将输入文本框的位置设置为相对,并且我尝试通过将删除图标的位置设置为绝对值来进行操作,但这不起作用。你能告诉我为什么这不起作用吗?

最佳答案

<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>

关于javascript - 在输入文本框中移动删除glyphicon,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46268083/

10-09 01:53