简体   繁体   English

如何在占位符后的搜索字段中 position cursor

[英]How to position cursor in search field after placeholder

I am using Vue for a small app and I have an input type search.我正在为一个小型应用程序使用 Vue,并且我有一个输入类型搜索。 The problem is that the cursor is displayed in the beginning of the input, but I want it to be displayed after the placeholder text.问题是 cursor 显示在输入的开头,但我希望它显示在占位符文本之后。 How can I achieve this?我怎样才能做到这一点?

Here is my code:这是我的代码:

 .search { height: 36px; width: 256px; margin-right: 42px; border: 1px solid #76b1c5; box-sizing: border-box; border-radius: 18px; }
 <input type="search" name="" id="" class="search" placeholder="search" />

and my CSS:和我的 CSS:

.search {
  height: 36px;
  width: 256px;
  margin-right: 42px;
  border: 1px solid #76b1c5;
  box-sizing: border-box;
  border-radius: 18px;
}

You cannot do this given your current setup.鉴于您当前的设置,您无法执行此操作。

The reason being that the cursor appears at the same place that the placeholder text starts.原因是 cursor 出现在占位符文本开始的同一位置。 So, no matter how you alter the placeholder text, or the cursor, they will always begin at the same place.因此,无论您如何更改占位符文本或 cursor,它们都将始终从同一位置开始。

If you wish to disconnect the cursor from the placeholder text, then you will need to create separate elements in order to accomplish that.如果您希望将 cursor 与占位符文本断开连接,则需要创建单独的元素才能完成此操作。 For example, using a label, or a div, or a span, or some combination of elements to have the text out of the flow of the document in order for it to be removable and separate from altering the layout.例如,使用 label、div、span 或某些元素组合使文本脱离文档流,以便将其移除并与更改布局分开。 In addition, this would mean implementing the placeholder logic, or leaving the placeholder in place as a label.此外,这意味着实现占位符逻辑,或将占位符保留为 label。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何调整搜索栏占位符文本的 position - How to adjust position of placeholder text of search bar 将 cursor 与以 position 开头的占位符对齐 - Align cursor to placeholder starting position 如何将光标位置放在contenteditable元素的中心对齐占位符的开头? - How to place cursor position at the start of center aligned placeholder of contenteditable element? 如何在居中占位符的开头定位HTML输入光标 - How to position HTML input cursor at beginning of centered placeholder 如何将光标位置设置为文本字段的初始位置? - How to set the cursor position to initial position of a text field? 缩小占位符文本后,如何使占位符和文本框光标居中? - How can I center the placeholder and text box cursor after shrinking the placeholder text? 使闪烁光标的位置居中而不更改占位符的位置 - centering the position of blinking cursor without changing the position of placeholder 如何在表单字段内设置文本光标的位置 - How to set the position of the text cursor inside a form field 如何在输入字段中居中占位符/输入文本,但保持光标左对齐 - How to center placeholder/input text in an input field, but keep the cursor left aligned cursor position 不在 Microsoft Edge 中 contentEditable div 中占位符的开头 - cursor position not at start of placeholder in contentEditable div in Microsoft Edge
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM