html - 如何将焦点框的宽度限制为网页上文本的长度
问题描述
我在表格中有一段文字。当您单击此文本时,焦点框应尽可能靠近此文本显示。使用我的代码,显示的焦点框与表格宽度一样宽。
如何将焦点框的宽度限制为文本的长度?
注意:文本必须在该表中。
我已经尝试过:
float: left;
,但随后文本不再居中。position: absolute; left: 50%; transform: translate(-50%, 0);
,但随后文本与之前的位置不完全相同(文本在获得焦点时会跳来跳去),这在 Safari 中不起作用。
这是我的代码:
<html>
<head>
<style type = "text/css">
div:focus {
outline-width: 2px;
outline-style: dotted;
outline-color: #ff0000;
}
</style>
</head>
<body>
<table width = "800px" align = "center">
<tr align = "center">
<td>
<div tabindex = "10">Click this text. The focus box should be as close as possible around this text.</div>
</td>
</tr>
</table>
</body>
</html>
解决方案
推荐阅读
- python - 无法使用 python 从 Json 文件中获取特定值
- bash - 无法在 Kali Linux 上解析 IP 地址 nmap
- javascript - 为什么内置的 confirm() 对话框很少使用?
- android - Scheduled JobService 仅在我打开我的应用程序时运行
- node.js - Node Js 复杂设计原则(Promise、async/await)
- google-cloud-speech - Google 语音转文本 API 密钥无效
- google-oauth - 向 G-Suite 、服务帐户的 OAuth 或服务器端 Web 应用程序的 OAuth 进行身份验证的最佳方法是什么
- sql-server - 升级 SQL Server 版本后出现问题,现在 services.msc 中有两台服务器
- javascript - 如何修复 Ajax 调用“参数字典包含一个空条目......”
- jquery - 同一日期但不同月份的月差