0

I am wondering how to properly use CSS in order to display an image based on valid form feedback?

Essentially I want to display a custom green check mark image or red X image on each form input line based on valid/invalid data, respectively. Is there a way to have this image appear inside the input box, right-aligned?

Thank you!

Update: Adding the image was as simple as including it within the "input:invalid" area of my css page. Now I just need to know how to have it only appear once and preferably right-aligned.

4
  • I think you could use div tag as the wrapper, and position:absolute. Commented Sep 17, 2018 at 0:45
  • are you using and frame work such as bootstrap? Commented Sep 17, 2018 at 0:49
  • It's a school assignment and we are supposed to do it without div. No boostrap or anything fancy, very simple html form with some css Commented Sep 17, 2018 at 0:58
  • 1
    Please provide a minimal reproducible example with what you have tried. Commented Sep 17, 2018 at 1:36

2 Answers 2

1

Please check this I think [this][1] is what you need:

<input type="text" name="text" value="" class="input">

.input{
background-image: url('https://dummyimage.com/20X20/ffffff/0a0a0a&text=x');
background-repeat: no-repeat;
background-position: right;
}
Sign up to request clarification or add additional context in comments.

2 Comments

Awesome, this is exactly what I came up with lol. You posted this as I was preparing my comment.
yah thats simple :)
0

The solution I came up with based on background image coding but within an input CSS container (if that makes sense... still new to this):

input:valid {
    background-color: #5CEC87;
    background-image: url(green_checkmark.png);
    background-repeat: no-repeat;
    background-position: right;
}


input:invalid {
    background-color: #FD9191;
    background-image: url(red_asterisk.png);
    background-repeat: no-repeat;
    background-position: right;
}

1 Comment

@AndreiGheorghiu Nothing! Just wanted to share my solution just in case anyone else stumbled upon this post with the same question and/or for personal future reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.