css - 在响应式图像上定位点
问题描述
我需要用 css 在一张图像上定位几个点。(见示例)
我正在使用下面的代码(对于点号 1):
<div id="photo1">
<div class="dot" style="left:calc(50px - 20px); top:calc(553px - 20px);">1</div>
<img id="big" src="/img/art/big32695-1.jpg" alt="example" title="example" />
</div>
和CSS:
#photo1 {position:relative; width:100%;}
.dot {position:absolute; width:40px; height:40px; background:#000; font-size:24px;line-height:40px; text-align:center; border-radius:50%; color:#fff; z-index:90;}
我没有任何问题,我的图片宽度仍然是 100%(例如 580 像素)。为此计算我的坐标 x 和 y。
但是,如果我减小屏幕宽度(智能手机或平板电脑),则当前图像宽度小于 100%。如果我假设图像宽度是 60%,我怎么能写这样的东西:
style="left:calc((60% * 50px) - 20px);top:calc((60% * 553px) - 20px);
调整我的第一个点关于当前图像宽度的位置。
你有什么想法 ?非常感谢所有回复或建议。
解决方案
尝试使用 % 定位元素。这将随着元素宽度的变化而改变宽度。
推荐阅读
- c++ - cblas_dcopy 对 memcpy_s 和 std::copy 的影响如何?
- google-cloud-platform - 需要帮助:NodeJs 应用部署在 Google Cloud Run 上,无法连接到 Google Cloud SQL 实例
- sql - 错误:频谱嵌套查询错误。引用嵌套表的子查询不能包含 DISTINCT 操作。红移
- java - MSAL4J - 令牌生成错误:未知或无效实例
- python - Bokeh Server:点击 Scatter 以在条形图中显示其他数据
- python - 从 Python 调用 Go 字符串返回函数
- python - Python Dask TypeError:无法解释'
' 作为数据类型 - reactjs - 如何将 SignaturePad 与 React TypeScript 一起使用
- mapping - 使用 R 基于 ShapeFile 裁剪栅格
- r - ggplot2中的刻面排序