Get the App
SLTechnology News&Howtos  ›  Development  › 

How to stretch background Picture by CSS+html+jquery

Shulou Source: shulou.com Published: 2022-06-03 03:52:20 10月03日 Update

This article will explain in detail how to stretch background pictures in CSS+html+jquery. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Method 1: CSS method, this method has a defect, is to set the dead height, and is not compatible with IE.

Untitled document body {width:100%; height:700px; margin:0; url (p_w_picpaths / banner11.jpg) no-repeat; padding:0; background-size:100% 100%;);} stretch the background picture

Method 2: jquery+CSS, all compatible

Untitled document body {width:100%; height:100%; margin:0; padding:0;} $(function () {$("body") .append (""); $("# main_bg") .append ("

"); cover (); $(window) .resize (function () {/ / browser window changes cover ();}); function cover () {var win_width=$ (window). Width (); var win_height=$ (window). Height (); $(" # bigpic "). Attr ({width:win_width,height:win_height});}

Method 3: html+css, this is a dead way, hehe, but the compatibility is very good.

Untitled document body {width:100%; height:100%; margin:0; padding:0;} # main_bg,#bigpic {width:100%; height:100%;}

This is the end of the article on "how to stretch background pictures in CSS+html+jquery". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Methods pictures backgrounds background pictures documents titles articles more good practical compatibility content methods that is articles browsers knowledge defects this is height Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info OPPO Reno Linux Microsoft Docker