CSS beginner tutorial: background image fills the entire screen

CSS beginner tutorial: background image fills the entire screen

If you want the entire interface to have a background image, you naturally think of adding a background to the body. The code is as follows:

body {
     width: 100%;
     height: 100%;
    /* Load background image */
    background: url("../static/images/index/backImg.jpg") no-repeat;
    /* The background image is centered vertically and horizontally*/
    background-position: center center;
    /* When the content height is greater than the image height, the background image is fixed relative to the viewport*/
    background-attachment: fixed;
    /* Let the background image scale based on the container size*/
    background-size: cover;
    /* Set the background color. The background color will be displayed during the background image loading process*/
  background-color: rgba(41, 50, 39, 1);
}

It is found that the height of the body is 0, so the picture cannot be displayed; the solution is to set the width and height of the HTML to 100%, so that the body has a value and the background image completely fills the entire screen.

Extensions

url(images/beijing.png)——the location of the image path;

no-repeat——the image is not repeated;

center 0px——center is positioned from the left side of the page, 0px is positioned from the top of the page;

background-position: center 0——is the positioning of the image, same as above;

background-size: cover; — Expands the background image to be large enough so that it completely covers the background area. Some parts of the background image may not be displayed in the background positioning area;

min-height: 100vh;——The height of the window. “Viewport” refers to the size of the visible area inside the browser, that is, window.innerWidth/window.innerHeight.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

<<:  Grid systems in web design

>>:  【Web Design】Share E-WebTemplates exquisite foreign web page templates (FLASH+PSD source file+HTML)

Recommend

Detailed explanation of mixins in Vue.js

Mixins provide distributed reusable functionality...

Use of Vue3 table component

Table of contents 1. Ant Design Vue 1. Official w...

Gitlab practical tutorial uses git config for related configuration operations

This article introduces the content related to gi...

Docker builds cluster MongoDB implementation steps

Preface Due to the needs of the company's bus...

How to use boost.python to call c++ dynamic library in linux

Preface Recently I started using robot framework ...

Some tips for writing high-performance HTML applications

How can you improve web page performance? Most de...

Vue achieves the top effect through v-show

html <div class="totop" v-show="...

MySQL transaction control flow and ACID characteristics

Table of contents 1. ACID Characteristics Transac...

Summary of Mysql common benchmark commands

mysqlslap Common parameter description –auto-gene...

Basic usage of find_in_set function in mysql

Preface This is a new function I came across rece...

Detailed explanation of the wonderful CSS attribute MASK

This article will introduce a very interesting at...

How to add links to FLASH in HTML and make it compatible with all major browsers

Look at the code first Copy code The code is as fo...

Detailed Analysis of Explain Execution Plan in MySQL

Preface How to write efficient SQL statements is ...

MySQL 5.7.18 installation tutorial and problem summary

MySQL 5.7.18 installation and problem summary. I ...