如何从坐标中获取 CSS 左、上、宽、高?

How to get the CSS left, top, width, height from coords?

使用图像映射工具,我制作了 5 个矩形框,但它们实际上需要变成 <input type=text style="position:absolute; left: ??px; top: ??px; width:??px; height:??px;" />,而不是矩形框,具有正确的左、上、宽、高

图像映射工具:

https://developer.cdn.mozilla.net/media/uploads/demos/s/u/summerstyle/365ccfd644f2b008c33f0046d2ba1a8f/summer-html-image-ma_1355318513_demo_package/index.html

代码生成:

<img src="a.png" alt="" usemap="#map" />
<map name="map">
    <area shape="rect" coords="961, 542, 1269, 611" />
    <area shape="rect" coords="245, 300, 606, 340" />
    <area shape="rect" coords="245, 247, 605, 286" />
    <area shape="rect" coords="245, 194, 605, 234" />
    <area shape="rect" coords="246, 142, 606, 183" />
</map>

如何将生成的坐标转换为 css 左、上、宽、高?

您有 <area> 个坐标 x1y1x2y2

这些是相对于你的图像的左上角的,我们可以假设它也是 <div> 的左上角,它将包含你的 <input> 元素 x1lefty1top

<div>应该有position: relative<input>position: absolute

或者,由于您似乎需要它们右对齐,您可以忽略 x1 值并设置 right: 0,然后您只需要 top 值。

这看起来确实是一种奇怪的布局方法,而不是使用正常的流程。