Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我知道我可以使用 JS/jQuery 设置一个元素以专注于文档加载:
$('#myInput').focus();
我的问题是是否可以仅使用 CSS 而不使用脚本来实现。
无法在 CSS 中设置焦点。这不是 CSS 设计的目的,因为它是一个行为问题。
如评论中所述,在 HTML 中,您可以使用该autofocus属性设置初始焦点。
autofocus