CSS background image adaptive element size

Source: Internet
Author: User

One or one methods for comparing soils are, placed on the ground floor.

Here's how:

CSS code:

img { position:absolute; z-index:-10; width:50%;}  

Html:

<src= "background picture path"/>  <span> Word on the background </span>  

At this point, the background can be automatically scaled, but the underlying image and the above word is unrelated, want to keep the corresponding relationship between the screen changes, need to use a percentage to indicate the spacing and size.
This approach can be achieved, but the personal feeling is not very normative, but there is no better way.

Second, the CSS3 has the background dimension attribute Background-size, is really the front-end gospel

Here's how:

Div {      width:200px;       height:100px;       background-image:url (bg.jpg);       background-size:100% 100%;  }  

Html:

< Div > picture extension </div>  

I only recorded the picture filled with the whole element, background-size and other uses to keep the picture aspect ratio.

CSS background image adaptive element size

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.