繁体   English   中英

CSS /背景尺寸不适用于Chrome

[英]css / background size is not working in chrome

我正在尝试将背景图像固定在浏览器的屏幕上,而无需任何滚动。 我已经尝试了所有可用的CSS属性,但仍然会出现。 我已附上图片以更好地了解

屏幕截图

我的CSS代码是

 particlesJS("particles-js", { "particles": { "number": { "value": 30, "density": { "enable": true, "value_area": 320 } }, "color": { "value": "#ffffff" }, "shape": { "type": "circle", "stroke": { "width": 0, "color": "#000000" }, "polygon": { "nb_sides": 5 }, "image": { "src": "img/github.svg", "width": 100, "height": 100 } }, "opacity": { "value": 0.5, "random": false, "anim": { "enable": false, "speed": 1, "opacity_min": 0.1, "sync": false } }, "size": { "value": 2, "random": true, "anim": { "enable": false, "speed": 25, "size_min": 0.1, "sync": false } }, "line_linked": { "enable": true, "distance": 150, "color": "#ffffff", "opacity": 0.4, "width": 1 }, "move": { "enable": true, "speed": 6, "direction": "none", "random": false, "straight": false, "out_mode": "out", "bounce": false, "attract": { "enable": false, "rotateX": 600, "rotateY": 1200 } } }, "interactivity": { "detect_on": "canvas", "events": { "onhover": { "enable": true, "mode": "grab" }, "onclick": { "enable": true, "mode": "push" }, "resize": true }, "modes": { "grab": { "distance": 140, "line_linked": { "opacity": 1 } }, "bubble": { "distance": 400, "size": 40, "duration": 2, "opacity": 8, "speed": 3 }, "repulse": { "distance": 200, "duration": 0.4 }, "push": { "particles_nb": 4 }, "remove": { "particles_nb": 2 } } }, "retina_detect": true }); /* ---- stats.js config ---- */ 
 canvas { display: block; vertical-align: bottom; } /* ---- particles.js container ---- */ #particles-js { position: absolute; width: 100%; height: 100%; } #particles-js:before { content: ""; position: absolute; z-index:-1; top: 0; left: 0; width: 100%; height: 100%; background-size: cover; background-image: url("https://blackshellmedia.com/wp-content/uploads/2015/03/Commercial-Buildings.jpg"); overflow: hidden; background-repeat: no-repeat; background-size: cover; background-repeat: no-repeat; background-position: 50% 50%; -webkit-filter: blur(4px); -moz-filter: blur(4px); -o-filter: blur(4px); -ms-filter: blur(4px); filter: blur(4px); } 
 <div id="particles-js"></div> <script src="https://cdnjs.cloudflare.com/ajax/libs/particlesjs/2.1.0/particles.js" defer="defer"></script> <script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script> 

请查找我的代码的结果,您将发现我面临的错误。

默认情况下, body标签要留一些余量,可以设置margin:0; 解决此问题。 检查下面的更新的片段...

 particlesJS("particles-js", { "particles": { "number": { "value": 30, "density": { "enable": true, "value_area": 320 } }, "color": { "value": "#ffffff" }, "shape": { "type": "circle", "stroke": { "width": 0, "color": "#000000" }, "polygon": { "nb_sides": 5 }, "image": { "src": "img/github.svg", "width": 100, "height": 100 } }, "opacity": { "value": 0.5, "random": false, "anim": { "enable": false, "speed": 1, "opacity_min": 0.1, "sync": false } }, "size": { "value": 2, "random": true, "anim": { "enable": false, "speed": 25, "size_min": 0.1, "sync": false } }, "line_linked": { "enable": true, "distance": 150, "color": "#ffffff", "opacity": 0.4, "width": 1 }, "move": { "enable": true, "speed": 6, "direction": "none", "random": false, "straight": false, "out_mode": "out", "bounce": false, "attract": { "enable": false, "rotateX": 600, "rotateY": 1200 } } }, "interactivity": { "detect_on": "canvas", "events": { "onhover": { "enable": true, "mode": "grab" }, "onclick": { "enable": true, "mode": "push" }, "resize": true }, "modes": { "grab": { "distance": 140, "line_linked": { "opacity": 1 } }, "bubble": { "distance": 400, "size": 40, "duration": 2, "opacity": 8, "speed": 3 }, "repulse": { "distance": 200, "duration": 0.4 }, "push": { "particles_nb": 4 }, "remove": { "particles_nb": 2 } } }, "retina_detect": true }); /* ---- stats.js config ---- */ 
 canvas { display: block; vertical-align: bottom; } /* ---- particles.js container ---- */ #particles-js { position: absolute; width: 100%; height: 100%; } #particles-js:before { content: ""; position: absolute; z-index:-1; top: 0; left: 0; width: 100%; height: 100%; background-size: cover; background-image: url("https://blackshellmedia.com/wp-content/uploads/2015/03/Commercial-Buildings.jpg"); overflow: hidden; background-repeat: no-repeat; background-size: cover; background-repeat: no-repeat; background-position: 50% 50%; -webkit-filter: blur(4px); -moz-filter: blur(4px); -o-filter: blur(4px); -ms-filter: blur(4px); filter: blur(4px); } body { margin: 0px; } 
 <div id="particles-js"></div> <script src="https://cdnjs.cloudflare.com/ajax/libs/particlesjs/2.1.0/particles.js" defer="defer"></script> <script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script> 

暂无
暂无

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

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