0

I need to add a second text (required) in input text, diferent style/position of placeholder. But when user clicks, it should disappear, like placeholder. It's possible?

<style>
  .inputDataText{
    padding:13px; 
    border-width:1px; 
    border-radius:9px; 
    border-style:solid; 
    border-color:#d9d9d9; 
    width:100%;
  }
  
</style>
<input id="demoTextBox" type="text" value="" class="inputDataText" placeholder="NAME">

Put an example image here:

Input image

4
  • If you specified a fixed width for the input item, the you can add spaces into your existing placeholder text to push some text to the right. These spaces are preserved when the text is being rendered Commented Sep 25, 2020 at 11:36
  • take a look at: codepen.io/Takumari85/pen/RaYwpJ the "Input with Label effects" at the bottom of the page. Its possible, yes, but you may need to work it out yourself. Commented Sep 25, 2020 at 11:36
  • Also, it is common to use * next to an input item and a note above or below all of them saying that these items are required. Commented Sep 25, 2020 at 11:38
  • Why not simply use "Name (required)" as a placeholder? Commented Sep 25, 2020 at 11:40

2 Answers 2

2

try

.inputDataText{
    padding:13px; 
    border-width:1px; 
    border-radius:9px; 
    border-style:solid; 
    border-color:#d9d9d9; 
    width:100%;
    box-sizing: border-box;
  }
  .inputwrapper{
   position: relative;
  }
 .inputwrapper::after {
    content: attr(data-required);
    position: absolute;
    right: 8px;
    top: 50%;
    font-size: 15px;
    transform: translateY(-50%);
    color: #ccc;
}
<div class="inputwrapper" data-required="(required)">
<input id="demoTextBox" type="text" value="" class="inputDataText" placeholder="NAME">
</div>

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

1 Comment

I was about to answer this question as well, but @Lalji was faster :). However, here's a link to my implementation which is very similar: codepen.io/zvona/pen/XWdGJNK
0

This could be done with the :empty pseudo selector

.inputDataText:empty::after {
  // show something
}

.inputDataText::after {
  // hide something
}

You will have to play with the exact CSS, but that's the gist

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.