简体   繁体   English

如何将感应式SVG背景绝对居中?

[英]How do I absolute center a responsive svg background?

I'm trying to achieve the following result: 我正在尝试实现以下结果: 在此处输入图片说明

The body has a black background and a fixed height of the browser window. 主体具有黑色背景,并且浏览器窗口的高度固定。 The graphic is a simple SVG with 50px margins on each side. 图形是一个简单的SVG,每边有50px的边距。 This ratio should stay consistent as the browser resizes. 随着浏览器调整大小,该比例应保持一致。

Implement the fixed-width black border as the stroke around the svg rectangle, which itself takes up the full width & height of the window. 将固定宽度的黑色边框实现为围绕svg矩形的笔触,该矩形本身占据了窗口的整个宽度和高度。 Something like this should do the trick for you (the snippit won't reder it properly so don't try running it in place--copy the code out to a separate file or to your page): 像这样的事情应该可以帮到您(snippit不会正确地重做它,所以不要尝试在原地运行它-将代码复制到单独的文件或页面中):

 <svg xmlns="http://www.w3.org/2000/svg"> <defs> <linearGradient id="bgGradient"> <stop offset="0%" stop-color="#fe7b47" /> <stop offset="100%" stop-color="#8cbef7" /> </linearGradient> </defs> <rect x="0" y="0" width="100vw" height="100vh" fill="url(#bgGradient)" stroke="#000000" stroke-width="100px" /> </svg> 

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

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