Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placeholder auto wrap inside a input field

Tags:

html

css

I need to put a long placeholder text inside a input field.

However, the placeholder will be cut due to its long text.

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<label for="password">
  <input id="password" name="user[password]" placeholder="Password (at least 8 letters, numbers, or punctuation marks)" size="30" type="password">
</label>

Is there any way to make it become this? enter image description here

like image 991
Coda Chang Avatar asked Sep 29 '16 03:09

Coda Chang


People also ask

How do you place placeholder inside input?

Use the ::placeholder pseudo-element to style your placeholder text in an <input> or <textarea> form element. Most modern browsers support this, but for older browsers, vendor prefixes will be required.

Can we wrap text in input field?

To wrap text in an Input Text Field, select 'textarea' in the properties palette. To wrap text in a regular text field, change it to multi line.


2 Answers

input{
  height:50px;
}

::-webkit-input-placeholder { /* Chrome/Opera/Safari */
  white-space:pre-line;  
  position:relative;
  top:-7px;
  
}
::-moz-placeholder { /* Firefox 19+ */
     white-space:pre-line;  
  position:relative;
  top:-7px;
}
:-ms-input-placeholder { /* IE 10+ */
    white-space:pre-line;  
  position:relative;
  top:-7px;
}
:-moz-placeholder { /* Firefox 18- */
     white-space:pre-line;  
  position:relative;
  top:-7px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<label for="password">
  <input id="password" name="user[password]" placeholder="Password (at least 8 letters, numbers, or punctuation marks)" size="30" type="password">
</label>
like image 102
Gowtham Avatar answered Oct 12 '22 13:10

Gowtham


I have tried it with division. You can try it also:

var placeholder = '<div>Password </div> <div>(at least 8 letters, numbers, or<br> punctuation marks)</div>';
$("body").click(function(e){
	if($("#input").html() === ""){
    $("#input").html("<div>Password </div> <div>(at least 8 letters, numbers, or<br> punctuation marks)</div>");
    $("#input").css("color", "gray")
  }
});
$('#input').focus(function(){
    if($(this).html() === placeholder){
        $(this).html("");
        $(this).css("color", "black")
    }
});
#input {
    -moz-appearance: textfield;
    -webkit-appearance: textfield;
    background-color: white;
    background-color: -moz-field;
    border: 1px solid darkgray;
    box-shadow: 1px 1px 1px 0 lightgray inset;  
    font: -moz-field;
    font: -webkit-small-control;
    margin-top: 5px;
    padding: 2px 3px;
    width: 240px;
    height: 30px;
    color: gray;
}
#input div{  
    float: left;
    clear: none; 
    height: 100%;
    vertical-align:middle;  
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="input" contenteditable><div>Password </div> <div>(at least 8 letters, numbers, or<br> punctuation marks)</div></div>
like image 25
Prifulnath Avatar answered Oct 12 '22 13:10

Prifulnath