Two methods to stretch the background image of a web page

Two methods to stretch the background image of a web page
There are two solutions:

One is CSS, using background-size:cover to achieve the stretching effect of the image, but IE8 and below do not support background-size, so you can use Microsoft's filter effect, but IE6 does not support it.

Copy code
The code is as follows:

body{background:url(bg.jpg) center center;background-size:cover;height:900px;width:100%;
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='bg.jpg', sizingMethod='scale');}

Another way is to use jQuery, dynamically insert a div in the body, and then include a picture in the div. When the browser window changes size, dynamically set the size of the background picture.
Copy code

Copy code
The code is as follows:

$(function(){
$("body").append("<div id='main_bg' style="position:absolute;"/>");
$("#main_bg").append("<img src='bg.jpg' id='bigpic'>");
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});
}

<<:  How to expand the disk space of Linux server

>>:  MySQL Interview Questions: How to Set Up Hash Indexes

Recommend

The whole process of configuring hive metadata to MySQL

In the hive installation directory, enter the con...

Tutorial on how to quickly deploy a Nebula Graph cluster using Docker swarm

1. Introduction This article describes how to use...

Linux method example to view all information of the process

There is a task process on the server. When we us...

Why is it not recommended to use an empty string as a className in Vue?

Table of contents Compare the empty string '&...

Complete steps for vue dynamic binding icons

0 Differences between icons and images Icons are ...

Full-screen drag upload component based on Vue3

This article mainly introduces the full-screen dr...

Implementation of mounting NFS shared directory in Docker container

Previously, https://www.jb51.net/article/205922.h...

Vue uses GraphVis to develop an infinitely expanded relationship graph

1. Go to the GraphVis official website to downloa...

JavaScript offsetParent case study

1. Definition of offsetParent: offsetParent is th...

Detailed explanation of views in MySQL

view: Views in MySQL have many similarities with ...

How to clear default styles and set common styles in CSS

CSS Clear Default Styles The usual clear default ...