html - 如何缩放我的 .svg 以填充整个视口?
问题描述
我的目标是用 svg 图像中定义的边框来框住整个页面。我认为我css
应该做的伎俩,但边框没有缩放到浏览器窗口。我的 .css 文件应该是什么样的?我应该修改svg
viewbox
吗?
我的代码:
html {
background: url(img/border.svg) no-repeat fixed;
background-size: cover;
background-size: 100% 100%;
}
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<p>some text.</p>
<svg viewBox="0 0 300 300" xmlns="http://www.w3.org/2000/svg">
<path d="m0 0.1375h198.7v111.92h-198.7v-111.92m2.3812 1.8521v98.954c0 1.3229 1.0583 2.3812 2.6458 2.3812h191.29l0.26459-98.69c0-1.5875-1.0583-2.6458-2.9104-2.6458z" fill="#d9d9d9"/>
</svg>
</body>
</html>
解决方案
您viewbox
是 300 x 300 将其更改为 1920 x 1080(您的 svg 大小)然后应该这样做并使其响应。
检查此代码:
body {
margin: 0;
padding: 0;
}
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<p>some text.</p>
<svg preserveAspectRatio="none" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1920 1080" style="enable-background:new 0 0 1920 1080;" xml:space="preserve">
<style type="text/css">
.st0{fill:#D9D9D9;}
</style>
<path class="st0" d="M0-0.7h1920v1081.5H0V-0.7 M23,17.2v956.2c0,12.8,10.2,23,25.6,23H1897l2.6-953.6c0-15.3-10.2-25.6-28.1-25.6
L23,17.2z"/>
</svg>
</body>
</html>
推荐阅读
- php - 调用数组上的成员函数 getPathName()
- javascript - 使用具有平均功能的 array.prototype.map
- java - 我可以通过 SSH 将键盘敲击发送到我的 Raspberry 以退出游戏模拟器吗?
- python - 从字符串数组中删除 nan
- wordpress - 将 WordPress 站点从 example.com/dir 移动到 example.com(example.com 上已经存在一个股票 WordPress 主题)
- javascript - 有没有更好的方法来添加/删除 Javascript 的菜单类
- python - 带有正则表达式的字符串的 Python 列表列表
- java - 将子选择休眠注释与实体一起使用
- javascript - JavaScript - 将 webm 转换为 mp4
- c# - Oracle 数字转换为 .Net 十进制