简体   繁体   English

如何使用伪元素将图像放置在文本框旁边?

[英]How to place image next to text box using pseudo Element?

I'm trying to place a "tick" image next to every valid textbox(client side validation) next. 我试图在每个有效的文本框(客户端验证)旁边放置一个“刻度”图像。 To do this I'm using psuado element. 为此,我使用了psuado元素。

CSS 的CSS

.valid {
border: 2px solid #a9cc56;
}

.valid:after {
content: "";
background: url('~/Areas/Waybill/Content/Images/icn-validation-valid.png') no-repeat;
width: 20px;
height: 20px;
float: left;
margin: 0 6px 0 0;
display: block;
}

.valid class is dynamically added to input element when input is valid. 当输入有效时,.valid类会动态添加到输入元素。 But Not firing the image. 但不发射图像。

Ray 射线

This could be a little problematic using only CSS, because :after element is a part of used element, but input CANNOT have any child elements. 仅使用CSS可能会有一些问题,因为:after元素是used元素的一部分,但是输入不能包含任何子元素。

You have to do something like: 您必须执行以下操作:

<input /><span></span>

CSS: CSS:

.valid + span:after {
content: "";
background: url('~/Areas/Waybill/Content/Images/icn-validation-valid.png') no-repeat;
width: 20px;
height: 20px;
float: left;
margin: 0 6px 0 0;
display: block;
}

Edit: 编辑:

Useful answer: https://stackoverflow.com/a/4660434/2746472 有用的答案: https : //stackoverflow.com/a/4660434/2746472

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM