Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move cursor small bit from left to right in a Input field

Tags:

html

css

I was created a div and a input field inside of the div. In input field, I set auto focus. When page load, the cursor focusing the input field. But the cursor in touch the border, so I can't clearly see the cursor. Is any way to move the cursor from left to right. I just want, the cursor should be touch the just front of the word Add a list. The clear example is inside of Stack Overflow page and the Title area. Please give your advise. Thank you.

<div  
    style = "white-space: normal;word-break: break-all; width: 240px; min-height: 35px; border-radius: 3px; margin-left: auto; margin-right: auto; text-align: center; background-color: #ffffff; margin-top: 5px; " >
    <input class = "list-name-field" id = "SAVE_LIST" autofocus="autofocus" style="width: 230px; min-height: 35px; border: 0; " type="text" name="" placeholder = "  Add a List...">
</div>
like image 964
Melbin Mathai Avatar asked Aug 11 '16 06:08

Melbin Mathai


People also ask

How do I move the input field cursor?

To move the cursor to the beginning of an input field:Use the setSelectionRange() method to move the cursor to the beginning of the input field. Call the focus() method on the input element. The focus method will move the cursor to the beginning of the element's value.

How do I put a cursor in a text field?

Sometimes all you have to do to make sure the cursor is inside the text box is: click on the text box and when a menu is displayed, click on "Format text box" then click on the "text box" tab and finally modify all four margins (left, right, upper and bottom) by arrowing down until "0" appear on each margin.

How do I change the cursor position in textarea?

To set the cursor at the end of a textarea: Use the setSelectionRange() method to set the current text selection position to the end of the textarea. Call the focus() method on the textarea element. The focus method will move the cursor to the end of the element's value.

What is caret position in Javascript?

The CaretPosition interface represents the caret position, an indicator for the text insertion point. You can get a CaretPosition using the Document. caretPositionFromPoint() method.


3 Answers

As @Rayon said, use padding style.

.list-name-field {
  padding: 0 10px;
}
<div style="white-space: normal;word-break: break-all; width: 240px; min-height: 35px; border-radius: 3px; margin-left: auto; margin-right: auto; text-align: center; background-color: #ffffff; margin-top: 5px;">
  <input class="list-name-field" id="SAVE_LIST" autofocus="autofocus" style="width: 230px; min-height: 35px; border: 0;" type="text" name="" placeholder="Add a List...">
</div>
like image 168
Mosh Feu Avatar answered Nov 15 '22 05:11

Mosh Feu


you can set with text-indent OR padding

input[type=text]{
  text-indent:15px;
}   

/*OR*/

input[type=text]{
  padding:0px 15px;
}
<div style="white-space: normal;word-break: break-all; width: 240px; min-height: 35px; border-radius: 3px; margin-left: auto; margin-right: auto; text-align: center; background-color: #ffffff; margin-top: 5px; ">

    <input class="list-name-field" id="SAVE_LIST" autofocus="autofocus" style="width: 230px; min-height: 35px; border: 0; " type="text" name="" placeholder="  Add a List...">
</div>
like image 34
Sandip - Frontend Developer Avatar answered Nov 15 '22 05:11

Sandip - Frontend Developer


In your Placeholder you have added a space, Simply remove that space, no need to add Css here.

Please try below.

<div  style = "white-space: normal;word-break: break-all; width: 240px; min-height: 35px; border-radius: 3px; margin-left: auto; margin-right: auto; text-align: center; background-color: #ffffff; margin-top: 5px; " >
							
							<input class = "list-name-field" id = "SAVE_LIST" autofocus="autofocus" style="width: 230px; min-height: 35px; border: 0; " type="text" name="" placeholder = "Add a List...">
							</div>
like image 34
Vatsal Shah Avatar answered Nov 15 '22 07:11

Vatsal Shah