[CSS] "CSS Secrets" Learning (iii)-Flexible background positioning

Source: Internet
Author: User

First, Background-position properties

With this property, you can also specify the position of the pattern from the edge of the container without determining the size of the container, but you need to specify a fallback scheme for browsers that do not support the property, otherwise the pattern will be placed by default in the upper-left corner.

1 <HTML>2 <Head>3     <MetaCharSet= "Utf-8">4     <title>Flexible background positioning</title>5     <styletype= "Text/css">6 Div{7 background:URL (http://csssecrets.io/images/code-pirate.svg)8 No-repeat bottom Right #58a;/*bottom right is the specified fallback scheme, avoid placing it in the upper left corner*/9 Ten background-position:Right 20px Bottom 10px; One  A Max-width:10em; - Min-height:5em; - padding:10px; the Color: White; - Font:100%/1 Sans-serif; -     } -     </style> + </Head> - <Body> +     <Div></Div> A </Body> at </HTML>

Second, Content-box

Each element has 3 rectangular borders, Border-box,padding-box,content-box, and by default, the background picture is placed from Padding-box.

If you add an attribute value:

Background-position:content-box, the background image will be placed from the content box position, in this way, you can also achieve the effect of the inner margin.

Third, calc () function

The offset of 20px from the right and below is actually the offset from above and below (100%-20px); You can use the Calc function to note that you need to add a space before +/-.

Background-position:calc (100%-20px), Calc (100%-20px);

[CSS] "CSS Secrets" Learning (iii)-Flexible background positioning

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.