Home Web Front-end HTML Tutorial CSS3 implements special shadow (study notes)_html/css_WEB-ITnose

CSS3 implements special shadow (study notes)_html/css_WEB-ITnose

Jun 24, 2016 am 11:49 AM

Learning source: MOOC http://www.imooc.com/view/240

Look at the renderings first↓↓↓↓↓↓↓↓↓↓↓↓ ↓↓↓↓↓↓↓↓↓

HTML structure

 1 <body> 2     <div class="wrap effect">     3     <!-- effect类:是阴影类,其他元素也可以使用 --> 4         <h1>Shadow Effect</h1> 5     </div> 6     <ul class="box"> 7         <li><img src="images/photo1.jpg" alt=""></li> 8         <li><img src="images/photo2.jpg" alt=""></li> 9         <li><img src="images/photo3.jpg" alt=""></li>10     </ul>11 </body>
Copy after login

CSS style (each browser prefix is ​​omitted)

 1 /*通用类*/ 2 body { font-family: Arial; font-size: 20px;} 3 body,ul {margin: 0; padding: 0; list-style: none;} 4 .wrap {width:70%; height:200px; margin:50px auto; background: #fff; } 5 .wrap h1 {font-size: 20px; text-align: center; line-height: 200px; } 6  7 /*弧度阴影*/ 8 .effect {  9     position: relative;10     box-shadow: 0px 1px 4px rgba(0,0,0,0.3),11     0 0 10px rgba(0,0,0,0.1) inset; 12     /*添加一个范围=4px的小阴影;再添加一个范围=10px的内阴影;*/13 }14 .effect:before,.effect:after {15     content: '';16     background: #f00;17     position: absolute;18     z-index: -2;19     top:50%; bottom:0; left:30px; right:30px;20     /*设置四个方向值,然后浏览器自动计算盒子的大小;*/21     box-shadow: 0px 0px 20px rgba(0,0,0,0.8);22     /*设置添加的盒子的阴影;*/23     border-radius: 100px/10px;24     /*添加圆角:水平方向圆角大小是100px/垂直方向圆角大小是10px;*/25 }26 27 /*翘边阴影*/28 .box{29     width:980px;30     height:auto;31     clear:both;32     overflow:hidden;33     margin:20px auto;34 }35 .box li{36     position: relative;37     /*以li为定位基准;*/38     width:300px;39     height:210px;40     float:left;41     background: #fff;42     margin:20px 10px;43     border:2px solid #efefef;44     box-shadow: 0px 1px 4px rgba(0,0,0,0.27);45     /*给li添加一个小小的阴影;*/46 }47 .box li img {48     display: block;49     width:290px;50     height:200px;51     margin:5px;52 }53 .box li:before{54     content: '';55     position: absolute;56     z-index: -3;57     width:90%;58     height:80%;59     left:18px;60     bottom:8px;61     box-shadow: 0px 8px 20px rgba(0,0,0,0.6);62     transform:skew(-12deg) rotate(-4deg);63     /*图形向右倾斜12度;并逆时针旋转4度;*/64 }65 .box li:after{66     content: '';67     position: absolute;68     z-index: -4;69     width:90%;70     height:80%;71     right:18px;72     bottom:8px;73     box-shadow: 0px 8px 20px rgba(0,0,0,0.6);74     transform:skew(12deg) rotate(4deg);75     /*图形向左倾斜12度;并顺时针旋转4度;*/76 }
Copy after login

Previously, I used a gray layer to overlay under other layers in PS to create a special shadow effect. The same idea was applied to CSS. praise!

Supplementary knowledge points↓↓↓↓↓↓↓

 1 1.box-shadow--添加一个或多个阴影 2     >1.功能:box-shadow--添加一个或多个阴影; 3     >2.语法:box-shadow:h-shadow v-shadow blur spread color inset; 4     >3.参数: 5         >>:h-shadow(必需):水平阴影的位置;允许负值; 6         >>:v-shadow(必需):垂直阴影的位置;允许负值; 7         >>:blur(可选):模糊距离; 8         >>:spread(可选):阴影的尺寸; 9         >>:color(可选):阴影的颜色;10         >>:inset(可选):将外部阴影(outset)改为内部阴影;11     >4.浏览器:IE9+/FF412 13 2.:before与:after 14     >1.:before选择器:在被选元素的内容前面插入内容;15     >2.:after选择器:在被选元素的内容后面插入内容;16     >3.说明:需要使用content属性来指定要插入的内容;17     >4.浏览器:IE8及更早版本中的:after,必须使用<!DOCTYPE>;18 19 3.transform--20     >1.功能:向元素应用2D或3D转换21     >1.语法:transform:none | transform-functions22     >2.参数:23         >>:skew(x-angle,y-angle):定义沿着X和Y轴的2D倾斜转换;24         >>:skewX(angle):定义沿着X轴的2D倾斜转换;25         >>:skewY(angle):定义沿着Y轴的2D倾斜转换;
Copy after login

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)

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

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 &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

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 &lt;datalist&gt; 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 &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

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.

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

See all articles