Table of Contents
doyue的手册
Home Web Front-end HTML Tutorial CSS3:背景_html/css_WEB-ITnose

CSS3:背景_html/css_WEB-ITnose

Jun 24, 2016 am 11:17 AM

细节注意

盒子: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开始位置的区分
Copy after login
文档:

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
Copy after login
结果1

结果2

Statement of this Website
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

HTML: The Structure, CSS: The Style, JavaScript: The Behavior HTML: The Structure, CSS: The Style, JavaScript: The Behavior Apr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML, CSS, and JavaScript: Web Development Trends The Future of HTML, CSS, and JavaScript: Web Development Trends Apr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The Future of HTML: Evolution and Trends in Web Design The Future of HTML: Evolution and Trends in Web Design Apr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative Overview HTML vs. CSS vs. JavaScript: A Comparative Overview Apr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Building the Structure of Web Pages HTML: Building the Structure of Web Pages Apr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

The Role of HTML: Structuring Web Content The Role of HTML: Structuring Web Content Apr 11, 2025 am 12:12 AM

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

See all articles