search
HomeWeb Front-endHTML TutorialCSS3:背景_html/css_WEB-ITnose

细节注意

盒子:border-box | padding-box | content-box用于background-origin背景的开始和background-clip的剪切位置。渐变也是生成一张图片相当url(),可以在前面或者后面加 repeat background-size其他等多层背景,最后加背景颜色哦,当然其他也能加,但是前面加的就覆盖最后的了。例子:240px 120px/100% 200px,这里面的背景开始位置position/背景尺寸size都是x和y方向,可以负值,可以百分比(以当前div的宽高,而不是背景图片的宽高的百分比)。position和origin开始位置的区分
文档:

doyue的手册

代码:
<!DOCTYPE html><html><head>  <meta charset="utf-8">  <meta name="viewport" content="width=device-width">  <title>JS Bin</title>  <style>    div{display:relative;float:left;}  .box0{width:100px;height:100px;background:red;opacity:0.1; transition:height 5s, width ,5s;}.box0:hover{ background:blue;width:200px;opacity:1;height:300px;}        .box1{      width:100px;height:230px;/*opacity:0.1; */      background:url("http://images.cnblogs.com/cnblogs_com/leee/801892/o_like.png");     /*background-size:contain; *//*将背景图像等比缩放到宽度或高度与容器的宽度或高度相等,背景图像始终被包含在容器内。*/     /* background-size:cover;*/ /*将背景图像等比缩放到完全覆盖容器,背景图像有可能超出容器。y轴方向北京图片显示完全,*/     /*background-size:100% 100%; *//*自定义背景图像宽高,为当前div宽高的百分比,如果小于div宽高,背景重复,需要设置repeat*/     /*background-size:100% 50%; */      /* background-size:100px 70px; *//*自定义背景图像大小,xy的大小,如果小于div宽高,背景重复,需要设置repeat*/      background-size:30px 70px;       transition:1s;     /*border:5px solid red;*//*没有顺序哦~*/      border:red solid  5px;     /*font:italic small-caps bold  16px/1 Simsun,arial,sans-serif;*/    }    .box1:hover{opacity:0.3;}        .box2{      height:400px;width:400px;  border:4px solid orange;  background:url(http://pic36.nipic.com/20131125/8821914_113934565000_2.jpg) 0 0/130px 140px  no-repeat,  no-repeat url(http://images.cnblogs.com/cnblogs_com/leee/801892/o_like.png) 100px 100px/130px 250px   ,   no-repeat  url("http://www.pp3.cn/uploads/201605/20160514011.jpg") 240px 120px/100% 100%,/*100% 100%超过了*/  no-repeat  url("http://www.pp3.cn/uploads/201605/20160514011.jpg") 190px -10px/180px 150px ,   -webkit-linear-gradient(bottom,yellow,yellowgreen) 0 0/100% 100%;/*渐变生成一张图,就相当于url()~*/    }   .box3{      height:400px;width:400px;      border:4px solid orange;      background:url(http://pic36.nipic.com/20131125/8821914_113934565000_2.jpg) 0 0/130px 140px  no-repeat,/*没有顺序哦~*/      no-repeat url(http://images.cnblogs.com/cnblogs_com/leee/801892/o_like.png) 100px 100px/130px 250px ,       url("http://www.pp3.cn/uploads/201605/20160514011.jpg") no-repeat 240px 120px/100% 100%,      no-repeat  url("http://www.pp3.cn/uploads/201605/20160514011.jpg") 190px -10px/180px 150px green;     /*注意,red 只能设置一次,且由于写在前面的背景会叠在之后的背景之上,所以背景色通常都定义在最后一组上,避免背景色将图像盖住。*/    }    .box4{ height:400px;width:400px;      padding-bottom:10px;/*剪切的时候,padding-box,就是padding也显示背景*/      border:40px dotted orange;      margin:50px;     background:  no-repeat url(http://images.cnblogs.com/cnblogs_com/leee/801892/o_like.png) 100px 100px/130px 100% border-box padding-box;      /*background-origin:border-box | padding-box | content-box*/       /*从border/padding/content区域(含border/padding/content)开始显示背景图像。 */      /*background-clip:border-box | padding-box | content-box | text      从border/padding/content区域(不含border/padding/content)开始向外裁剪背景。 */    }  </style></head><body><div class="box0"></div>  <div class="box1">这是一段字体</div>  <div class="box2"></div>  <div class="box3"></div>  <div class="box4"></div></body></html
结果1

结果2

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?Mar 04, 2025 pm 12:32 PM

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

How do I use HTML5 form validation attributes to validate user input?How do I use HTML5 form validation attributes to validate user input?Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

What are the best practices for cross-browser compatibility in HTML5?What are the best practices for cross-browser compatibility in HTML5?Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

How to efficiently add stroke effects to PNG images on web pages?How to efficiently add stroke effects to PNG images on web pages?Mar 04, 2025 pm 02:39 PM

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

What is the purpose of the <datalist> element?What is the purpose of the <datalist> element?Mar 21, 2025 pm 12:33 PM

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <meter> element?What is the purpose of the <meter> element?Mar 21, 2025 pm 12:35 PM

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

How do I use the HTML5 <time> element to represent dates and times semantically?How do I use the HTML5 <time> element to represent dates and times semantically?Mar 12, 2025 pm 04:05 PM

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

What is the purpose of the <progress> element?What is the purpose of the <progress> element?Mar 21, 2025 pm 12:34 PM

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment