css - SVG 边框图像在 Chrome 上完美,在 Firefox 上拉伸
问题描述
我的问题是这样的:
我在边框图像 CSS 上有一个 SVG 图像。它在 Chrome 上呈现我想要的效果,但在 Firefox 上被拉伸了。
我必须修改 SVG 内部的宽度和高度值来“修复”它,但是当我只需要 3 个点时,它会显示很多点。
更明确地说:https ://codepen.io/benCat/pen/EeJmwL
.container {
text-align: center;
}
h1 {
margin-bottom: 2em;
}
hr {
position: relative;
width: 45em;
border-width: 0 0 1em;
border-style: solid;
border-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 2 1" width="50" height="4" xml:space="preserve" preserveAspectRatio="meet"><circle fill="rgba(136, 165, 122, 0.4)" cx="1" cy="0.5" r="0.5"/></svg>') 0 0 100% repeat;
}
<div class="container">
<h1>Normaly, 3 perfect dots with lot of space between</h1>
<hr>
</div>
我可以通过这种方式解决它吗?
使用边框图像制作一个简单的点我错了吗?
编辑:出于某些原因,我想用 SVG 打点,无论如何,但仅限于 SVG :)
谢谢 !
解决方案
它preserveAspectRatio
在 Firefox 中无法按预期工作(至少在数据 uris 中没有)。如果你需要它工作,你需要保持比例:如果你想要viewBox='0 0 2 1'
并且 width='50'
你不需要height='25'
height='4'。粗略地说,这可能不是您所需要的,但您明白了要点。另外:在 CSS 中最好使用编码的 SVG
.container {
text-align: center;
}
h1 {
margin-bottom: 2em;
}
hr {
position: relative;
width: 45em;
border-width: 0 0 1em;
border-style: solid;
border-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' version='1.1' viewBox='0 0 2 1' width='50' height='25' xml:space='preserve' preserveAspectRatio='meet'%3E%3Ccircle fill='rgba(136, 165, 122, 0.4)' cx='1' cy='0.5' r='0.5'/%3E%3C/svg%3E") 0 0 100% repeat;
}
<div class="container">
<h1>Normaly, MANY perfect dots with SOME space between</h1>
<hr>
</div>
更新:为了只获得 3 分,您需要像这样更改 SVG。
.container {
text-align: center;
}
h1 {
margin-bottom: 2em;
}
hr {
position: relative;
width: 45em;
border-width: 0 0 1em;
border-style: solid;
border-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' version='1.1' viewBox='-7 0 16 1' width='400' height='25' xml:space='preserve' preserveAspectRatio='meet'%3E%3Ccircle fill='rgba(136, 165, 122, 0.4)' cx='1' cy='0.5' r='0.5'/%3E%3C/svg%3E") 0 0 100% repeat;
}
<div class="container">
<h1>Normaly, 3 perfect dots with lot of space between</h1>
<hr>
</div>
推荐阅读
- php - 如何在 Laravel 5.6 中通过 html 表单选择和输入同时添加信息?
- javascript - 如何使用 jquery load 调用 php 文件中的函数?
- python-3.x - Python中的while循环永远循环
- python - 尝试在 jupyter notebook 中使用 tensorflow 时出错
- azure - 如何通过 Azure Logic App 和 Outlook 发送 html 电子邮件
- c# - 为什么 AutoMapper 将整数字段映射到对象?
- python - Django Rest Framework - 在 POST 上创建外键对象
- javascript - 如何在不填充磁盘的情况下测试 IndexedDB 'QuotaExceededError'?
- python - Cmd + z 不会关闭python
- python - 张量流中的可微直方图