<分区>
<分区>
我试图通过使用 psudo
类 after
在每个 input
元素上添加一个 close
按钮。但没有工作。同样适用于 button
元素。
这是我的代码:
.textBox {
padding: 15px ;
text-decoration: none;
display: inline-block;
position: relative;
}
.textBox:after {
content: "";
width: 15px;
height: 15px;
background: #ff0 url("http://www.gentleface.com/i/free_toolbar_icons_16x16_black.png") no-repeat -30px -75px;
border:1px solid red;
display: inline-block;
border:1px solid red;
}
<input type="text" class="textBox" value="mytext" name="" id="">
<button class="textBox">Click me</button>
最佳答案
使用包装 div
并在那里设置 textBox
类而不是 input
.textBox {
padding: 15px ;
text-decoration: none;
display: inline-block;
position: relative;
}
.textBox:after {
content: "";
width: 15px;
height: 15px;
background: #ff0 url("http://www.gentleface.com/i/free_toolbar_icons_16x16_black.png") no-repeat -30px -75px;
border:1px solid red;
display: inline-block;
border:1px solid red;
}
<div class="textBox">
<input type="text" value="mytext" name="" id="">
</div>
<button class="textBox">Click me</button>
关于html - `:after` - 伪类不适用于 `input` 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51168755/