html - `:after` - 伪类不适用于 `input` 元素

标签 html css

<分区>

我试图通过使用 psudoafter 在每个 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/

上一篇:javascript - 蓝色窗口在 3 秒后消失

下一篇:javascript - 当浏览器宽度/高度改变时自动调整图像大小

相关文章:

css - 你可以在 sass 对象值中有一个数组吗?

css - 宽度对齐 block

HTML 标签索引问题

javascript - 如何使用 document.querySelector 从使用 document.querySelector 的节点中选择特定的文本输出?

javascript - HTML5 是否支持跨窗口消息传递?

javascript - 在选择的多个元素上强制确定大小

html - 嵌入 TTF 字体@Font-face

css - 从 Bootstrap anchor 链接中删除默认样式

html - v4 bootstrap 全高侧边栏

html - 如何在CSS中实现最小左/右