Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of clipping and setting the size and position of the background image by CSS3

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "the method of cutting and setting the size and position of the background picture by CSS3". In the daily operation, I believe that many people have doubts about the method of cutting and setting the size and position of the background picture by CSS3. The editor consulted all kinds of materials and sorted out a simple and easy-to-use operation method. I hope it will be helpful for you to answer the doubt that CSS3 has on the method of cutting and setting the size and position of the background picture. Next, please follow the editor to study!

Background clipping

CSS Code copies content to the clipboard

Background-clip:border-box | padding-box | content-box | text

Used to specify whether the background contains a border,padding other than content. The default value is border-box, that is, background starts rendering from places including border, and the default performance of IE is equivalent to border-box.

The background is drawn (rendered) from border (that is, including border)

CSS Code copies content to the clipboard

# background-clip-border {

-moz-background-clip:border-box; / * For Firefox * /

-webkit-background-clip:border-box; / * For Chrome, Safari * /

-Or For Opera backgroundLay clipRod borderlym box; / * RB * /

-ms-background-clip:border-box; / * For IE * /

Background-clip:border-box; / * For Future * /

}

The background is drawn from padding (that is, including padding):

CSS Code copies content to the clipboard

# background-clip-padding {

-moz-background-clip:padding-box; / * For Firefox * /

-webkit-background-clip:padding-box; / * For Chrome, Safari * /

-Or For Opera backgroundLay clips paddingwo box; / * background * /

-ms-background-clip:padding-box; / * For IE * /

Background-clip:padding-box; / * For Future * /

}

The background is drawn from content (that is, the content part):

CSS Code copies content to the clipboard

# background-clip-content {

-moz-background-clip:content-box; / * For Firefox * /

-webkit-background-clip:content-box; / * For Chrome, Safari * /

-ORFT For Opera For Opera; / * RFT * /

-ms-background-clip:content-box; / * For IE * /

Background-clip:content-box; / * For Future * /

}

Crop the background as the fill color of the text:

CSS Code copies content to the clipboard

/ * if your browser supports the text value, you will see that the color of this paragraph directly uses the background color: red, and the background will be cut out and no longer displayed * /

# background-clip-text {

Background-color:#f00

-webkit-text-fill-color:transparent

-webkit-background-clip:text; / * For Chrome, Safari * /

Background-clip:text; / * For Future * /

}

Background picture location

CSS Code copies content to the clipboard

Background-origin:border-box | padding-box | content-box

Calculate the background-position of the background map with border (that is, including border) as the origin:

CSS Code copies content to the clipboard

# background-origin-border {

-moz-background-origin:border-box; / * For Firefox * /

-webkit-background-origin:border-box; / * For Chrome, Safari * /

-Or For Opera backgroundmusic box; / * house * /

-ms-background-origin:border-box; / * For IE * /

Background-origin:border-box; / * For Future * /

}

Calculate the background-position of the background map with padding (that is, including padding) as the origin:

CSS Code copies content to the clipboard

# background-origin-padding {

-moz-background-origin:padding-box; / * For Firefox * /

-webkit-background-origin:padding-box; / * For Chrome, Safari * /

-Or For Opera backgroundPassbox; / * house * /

-ms-background-origin:padding-box; / * For IE * /

Background-origin:padding-box; / * For Future * /

}

Calculate the background-position of the background map with content (that is, starting from content) as the origin:

CSS Code copies content to the clipboard

# background-origin-content {

-moz-background-origin:content-box; / * For Firefox * /

-webkit-background-origin:content-box; / * For Chrome, Safari * /

/ * For Opera * /

-ms-background-origin:content-box; / * For IE * /

Background-origin:content-box; / * For Future * /

}

Picture background size

CSS Code copies content to the clipboard

Background-size: [length | percentage | auto] {1Jing 2} | cover | contain

Used to set the size of the background image, there are two optional values, the first value is used to specify the width of the background image, and the second value is used to specify the height of the background image. If only one value is specified, the second value defaults to auto

Numerical representation:

CSS Code copies content to the clipboard

# background-size {

Background-size:300px 100px

}

Percentage representation:

CSS Code copies content to the clipboard

# background-size2 {

Background-size:40% 80%

}

Expand the picture proportionally to fill the element, that is, the cover value:

CSS Code copies content to the clipboard

# background-size3 {

Background-size:cover

}

Proportionally reduce the picture to fit the size of the element, that is, the containment value:

CSS Code copies content to the clipboard

# background-size4 {

Background-size:contain

}

Fill the element with the size of the picture itself, that is, the autovalue:

CSS Code copies content to the clipboard

# background-size5 {

Background-size:auto

}

At this point, the study on "CSS3's method of cropping and setting the size and position of background pictures" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report