Use CSS to add background image methods to unknown, wide-height elements

Source: Internet
Author: User
Adds a background image to an element of the page, which cannot be displayed when no specific width is specified.

1. Add a background map

HTML code:

<! DOCTYPE html>

We can look at the page effect:

In order to adapt to different terminals of the screen size, we can not write the width of the dead, how to do? You can take the following methods:

HTML code:

<! DOCTYPE html>

Take a look at the page effect:

Mobile page Effects

Note: If you remove the div, directly add the style to the body, the PC browser can display, the Android phone can also be displayed, but in the Apple phone is not displayed. Repeated tests repeatedly, all reproduce this bug (if a friend encountered such a positive solution to the problem, welcome advice!) )

(for Apple models)

2. Add a background image via the IMG tag

HTML code:

<! DOCTYPE html>

When I look at the page effect, we find that the picture is rendered in hundred percent actual size, which is obviously not the effect we want.

Very similar to the example above, we just need a little modification.

HTML code:

<! DOCTYPE html>

Viewing page effects under different analog models can be achieved by:

About the Background-size attribute, which is defined by the

Related Article

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.