html - 网页上的图像周围看不到虚线焦点线
问题描述
当焦点在图像上时,我想在图像周围有一条虚线。但这在我添加后不起作用outline-style: dotted;
。我可以删除style = "display:block"
,但是虚线没有完全显示在图像周围。我的代码在 Mozilla Firefox 中运行良好,但在 Microsoft Edge、Internet Explorer、Google Chrome、Opera 和 Safari 中无法运行。
我该怎么做才能使图像周围的虚线在所有浏览器中都可见?
这是我的代码:
<html>
<head>
<style type = "text/css">
a:focus {
outline-width: 2px;
outline-style: dotted;
outline-color: #ff0000;
}
</style>
</head>
<body>
<input type = "text" tabindex = "10" style = "width:200px" value = "Click here and then press 'Tab'"><p>
<a href = "" tabindex = "20">Link 1</a><p>
<a href = "" tabindex = "30"><img src = "image.gif" style = "display:block"></a><p>
<a href = "" tabindex = "40">Link 2</a><p>
</body>
</html>
解决方案
尝试inline-block
使用父锚点和block
图像。这在 Edge/Chrome 中对我有用。
<html>
<head>
<style type = "text/css">
a:focus {
outline-width: 2px;
outline-style: dotted;
outline-color: #ff0000;
}
</style>
</head>
<body>
<input type = "text" tabindex = "10" style = "width:200px" value = "Click here and then press 'Tab'"><p>
<a href = "" tabindex = "20">Link 1</a><p>
<a href = "" tabindex = "30" style = "display:inline-block"><img src = "image.gif" style = "display:block"></a><p>
<a href = "" tabindex = "40">Link 2</a><p>
</body>
</html>
推荐阅读
- javascript - 如何在 HTML/CSS 中添加特定于设备的变量?
- python-3.x - 为什么在我的 Docker 映像上安装 python-psycopg2 不能防止随后出现“没有名为 'psycopg2' 的模块”错误?
- python - 查找具有连续但奇数日期的百分比差异和差异
- javascript - 如何在 MongoDB 中插入带有子文档的文档
- jquery - jQuery |for 循环创建唯一元素类
- git - `git add -all` 的快捷方式是如何制作的(在终端中)?
- python - 如何使用熊猫数据框按秒重新采样累积的数据并每天重置
- c# - Any(LINQ) 中的语句 lambda
- html - 为什么我的锚链接不能跳转到特定部分?
- python - 错误:命令已存在于 cog - Discord.py