CSS3 background

CSS3 Background

CSS3 includes several new background properties that provide greater control over background elements.

In this chapter you will learn about the following background properties:

  • background-image

  • background-size

  • background-origin

  • background-clip


##CSS3 background-image Attribute

In CSS3, you can add a background image through the background-image attribute.

Different background images and images are separated by commas, and the one displayed at the top of all images is the first one.

    php中文网(php.cn)  

正能量

你是否经常狠不下心来做事,对自己不够狠,对别人也不够狠。所以,你总是黏黏糊糊,总是不忍心去拒绝别人,总是下不了决心让自己过的更好,总是缠绵过往不能自拔……完了,优柔寡断的你,必须狠一次,否则你永远也活不出自己

别为小小的委屈难过,人生在世,注定要受许多委屈。一个人越是成功,他所遭受的委屈也越多。要使自己的生命获得极值和炫彩,就不能太在乎委屈,不能让它们揪紧你的心灵、扰乱你的生活。你要学会一笑置之,超然待之,要学会转化势能。智者懂得隐忍,原谅周围的那些人,让我们在宽容中壮大。

Run the program and try it


You can set multiple different attributes for different pictures

    php中文网(php.cn)  

正能量

你是否经常狠不下心来做事,对自己不够狠,对别人也不够狠。所以,你总是黏黏糊糊,总是不忍心去拒绝别人,总是下不了决心让自己过的更好,总是缠绵过往不能自拔……完了,优柔寡断的你,必须狠一次,否则你永远也活不出自己

别为小小的委屈难过,人生在世,注定要受许多委屈。一个人越是成功,他所遭受的委屈也越多。要使自己的生命获得极值和炫彩,就不能太在乎委屈,不能让它们揪紧你的心灵、扰乱你的生活。你要学会一笑置之,超然待之,要学会转化势能。智者懂得隐忍,原谅周围的那些人,让我们在宽容中壮大。

Run the program and try it


CSS3 background-size attribute

background-size specifies the size of the background image. Before CSS3, the background image size was determined by the actual size of the image.

Background images can be specified in CSS3, allowing us to re-specify the size of the background image in different environments. You can specify the size in pixels or percentage.

The size you specify is a percentage of the width and height of the parent element.

    php中文网(php.cn)  

人心灵的伤痛若无知己来抚慰,便会荒芜;人的欢乐若知己来共享,再多的快乐也是悲伤。知己之于人,本是必不可缺。一个人的痛苦要找人倾诉,一个人的愁绪要有人来排解。人若没有知己,心灵便是一片怎样的荒凉。

原始图片: Flowers

Run the program and try it

    php中文网(php.cn)  
人心灵的伤痛若无知己来抚慰,便会荒芜;人的欢乐若知己来共享,再多的快乐也是悲伤。知己之于人,本是必不可缺。一个人的痛苦要找人倾诉,一个人的愁绪要有人来排解。人若没有知己,心灵便是一片怎样的荒凉。

Run the program and try it


CSS3 background-Origin attribute

The background-Origin attribute specifies the location area of the background image.

Background images can be placed in the content-box, padding-box, and border-box areas.

    php中文网(php.cn)  

background-origin:border-box:

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.

background-origin:content-box:

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.

Run the program and try it


CSS3 background-clip property

The background-clip background clipping property in CSS3 starts drawing from the specified position

    php中文网(php.cn)  

没有背景剪裁 (border-box没有定义):

Lorem Ipsum Dolor

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.

background-clip: padding-box:

Lorem Ipsum Dolor

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.

background-clip: content-box:

Lorem Ipsum Dolor

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.

Run the program to try it


New background attributes

Order Description CSS
background-clip Specifies the drawing area of the background. 3
background-origin Specifies the positioning area of the background image. 3
background-size Specifies the size of the background image. 3



Continuing Learning
||
php中文网(php.cn)

正能量

你是否经常狠不下心来做事,对自己不够狠,对别人也不够狠。所以,你总是黏黏糊糊,总是不忍心去拒绝别人,总是下不了决心让自己过的更好,总是缠绵过往不能自拔……完了,优柔寡断的你,必须狠一次,否则你永远也活不出自己

别为小小的委屈难过,人生在世,注定要受许多委屈。一个人越是成功,他所遭受的委屈也越多。要使自己的生命获得极值和炫彩,就不能太在乎委屈,不能让它们揪紧你的心灵、扰乱你的生活。你要学会一笑置之,超然待之,要学会转化势能。智者懂得隐忍,原谅周围的那些人,让我们在宽容中壮大。

submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!