CSS for responsive full-screen backgrounds

Source: Internet
Author: User

Fills the entire viewport with Background-size:cover in CSS

Attention:

A background image of the 5000px*5000px in the PC-side scaling is basically meet the requirements will not appear fuzzy distortion;

But using such a large picture on the mobile side is a waste of resources, and a large map can slow loading, especially under the mobile network.

A relatively small picture can be set on the mobile side using media queries

body{/*loading the background map*/background-image:url (images/background-photo.jpg);/*The background chart is centered vertically and horizontally*/background-Position:center Center;/*uneven layout of the background*/background-repeat:no-repeat;/*When the content height is greater than the height of the picture, the position of the background image is fixed relative to viewport*/background-attachment:fixed;/*let the background map scale based on container size*/background-Size:cover;/*sets the background color, which is displayed during the background image loading*/background-color: #464646;} 
@media only screen and (max-width:767px) {  body {    background-image:url (images/ Background-photo-mobile-devices.jpg);   }}

  

CSS for responsive full-screen backgrounds

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.