简体   繁体   English

文字即将消失<svg><rect> 1000 倍的盒子一次,但在 safari 浏览器上总是重现这个错误

[英]text is going out of <svg><rect> box once in 1000x times but on safari browser always reproduce this bug

Im trying to fix this bug, and I have tried alot things but nothing help, if I give value of x='23%' like <text id="badgeText" x = "23% ... I can fix bug on safari but than bug start repodruce everytime on other browsers(mozila,chrome etc...), anyhow the bug is reproducing once in many times on other browsers ...我试图修复这个错误,我已经尝试了很多东西但没有任何帮助,如果我给出 x='23%' 的值,比如<text id="badgeText" x = "23% ...我可以修复 safari 上的错误但是,除了在其他浏览器(mozila、chrome 等)上每次都开始重现错误之外,无论如何,该错误在其他浏览器上多次重现...

bug image错误图像

<div class="CoveoShowIfFieldValue"  data-field="@isRecommended" data-field-value="True">
<svg height="25px" style="overflow:visible!important;">
    <g id="recommendedBadge" style="object-fit:contain!important;">
        <rect x="0" y="0" rx="15px" ry="15px"/>
        <text id="badgeText" y="66%" font-family="Metric" text-anchor="middle" class="CoveoText" data-value="RECOMMENDED" style="text-transform: uppercase;"></text>
        <g class="tooltip" transform="translate(21,62)">
            <rect x="-6%" width="450" y="-35" height="25" rx="5px" ry="5px"/>
            <text y="-31" dy="1em" font-family="Metric" text-anchor="middle" font-weight="100" class="CoveoText" data-value="RecommendedTooltip"></text>
        </g>
    </g>
</svg> </div>

It's not a bug:这不是一个错误:
You need to add some width related properties like width or a viewBox .您需要添加一些与宽度相关的属性,例如widthviewBox

Otherwise a browser can't tell how to render a relative unit within a svg element.否则浏览器无法判断如何在 svg 元素中呈现相对单位。

Some browsers might be more forgiving by guessing or setting default width values as fallbacks.一些浏览器可能会通过猜测或设置默认宽度值作为后备来更宽容。 (Currently most firefox and chromium based browsers use 300px as a fallback). (目前大多数基于 firefox 和 chromium 的浏览器使用 300px 作为后备)。

 <style> svg { border: 1px solid red; height: 25px; } text { fill: #fff; } </style> <h2>Use viewBox</h2> <svg viewBox="0 0 450 25" style="overflow:visible!important;"> <g id="recommendedBadge"> <rect x="0" y="0" rx="15" ry="15" width="100%" height="25" /> <text id="badgeText" x="50%" y="50%" dy="2" dominant-baseline="middle" font-family="Metric" text-anchor="middle" class="CoveoText" data-value="RECOMMENDED" style="text-transform: uppercase;"> Badge Text </text> <g class="tooltip" transform="translate(0 25)"> <rect x="0" y="0" width="100%" height="100%" rx="5" ry="5" fill="red" /> <text x="50%" y="50%" dy="5" font-family="Metric" text-anchor="middle" font-weight="100" class="CoveoText" data-value="RecommendedTooltip">tooltip</text> </g> </g> </svg> <br><br><br> <h2>Use width</h2> <svg height="25" width="100%" style="overflow:visible!important;"> <g id="recommendedBadge"> <rect x="0" y="0" rx="15" ry="15" width="100%" height="25" /> <text id="badgeText" x="50%" y="50%" dy="2" dominant-baseline="middle" font-family="Metric" text-anchor="middle" class="CoveoText" data-value="RECOMMENDED" style="text-transform: uppercase;"> Badge Text </text> <g class="tooltip" transform="translate(0 25)"> <rect x="0" y="0" width="100%" height="100%" rx="5" ry="5" fill="red" /> <text x="50%" y="50%" dy="5" font-family="Metric" text-anchor="middle" font-weight="100" class="CoveoText" data-value="RecommendedTooltip">tooltip</text> </g> </g> </svg>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM