Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何使文本输入与中心对齐,但在聚焦时使光标向左对齐?_Html_Css - Fatal编程技术网

Html 如何使文本输入与中心对齐,但在聚焦时使光标向左对齐?

Html 如何使文本输入与中心对齐,但在聚焦时使光标向左对齐?,html,css,Html,Css,我有如下输入文本: <input type="text" placeholder="mm/dd/yyyy" style="text-align:center"/> 占位符正确地居中显示,但当我聚焦于字段时,光标也位于文本字段的中心,我希望它位于占位符的左侧。 如何仅对齐光标?您可以使用选择器 您可能还希望使用选择器,以便占位符不会移动 输入,输入::占位符{ 文本对齐:居中; } 输入:焦点{ 文本对齐:左对齐; } 不寻常的要求,绝妙的回答。你不需要同时选择输入和占位符,因

我有如下输入文本:

<input type="text" placeholder="mm/dd/yyyy" style="text-align:center"/>

占位符正确地居中显示,但当我聚焦于字段时,光标也位于文本字段的中心,我希望它位于占位符的左侧。 如何仅对齐光标?

您可以使用选择器

您可能还希望使用选择器,以便占位符不会移动

输入,输入::占位符{
文本对齐:居中;
}
输入:焦点{
文本对齐:左对齐;
}

不寻常的要求,绝妙的回答。你不需要同时选择输入和占位符,因为当你失去焦点时,它会回到中心,不确定这是否正确desirable@ZohirSalak-是的,我也不确定。可能只有占位符应该居中。在这种情况下,Op只能选择占位符