0

Is it possible to display dynamic texts contents inside an HTML input element, some thing similar to how chrome browsers CTRL + F works.

Like it shows the number of hits in the page.

Can anyone please help, if possible how or share some useful materials to achieve the same?

enter image description here

7
  • Please show your code! What you've tried! Commented Feb 25, 2016 at 5:19
  • yes you can do it, using css, jquery. Commented Feb 25, 2016 at 5:21
  • Is it possible to display dynamic texts inside an HTML input element, You mean highlight the matching content in an input value? Commented Feb 25, 2016 at 5:24
  • @gurvinder372 ... no I have edited the question, please see. Commented Feb 25, 2016 at 5:31
  • If I got your question right, do you mean HTML text highlight? like in this question: stackoverflow.com/questions/119441/highlight-a-word-with-jquery Commented Feb 25, 2016 at 6:30

1 Answer 1

3

You can easily achieve this using a combination of relative and absolute positioning on the parent and child elements like this:

.field {
  position: relative;
  display: inline-block;
}
.field__input {
  padding-right: 40px;
}
.field__helper {
  position: absolute;
  right: 5px;
  top: 4px;
  color: #999;
  font-size: 12px;
}
/* this is just fluff to make it look nicer */
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
<div class="field">
  <input type="text" value="find" class="field__input">
  <span class="field__helper">1 of 5</span>
</div>

We use a relatively positioned parent (.fieldRow) to wrap around the input field. Then, we use a span (.helper) containing the text we want to display and using position: absolute; we can position it to the right of the input field. Last of all, we need a little padding on the right hand side of the input to stop the inputted value from bleeding into our helper text.

Sign up to request clarification or add additional context in comments.

Comments

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.