search
HomeWeb Front-endHTML TutorialCSS3 implements special shadow (study notes)_html/css_WEB-ITnose

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 id="Shadow-Effect">Shadow Effect</h1> 5     </div> 6     <ul class="box"> 7         <li><img src="/static/imghwm/default1.png"  data-src="images/photo1.jpg"  class="lazy" alt=""></li> 8         <li><img src="/static/imghwm/default1.png"  data-src="images/photo2.jpg"  class="lazy" alt=""></li> 9         <li><img src="/static/imghwm/default1.png"  data-src="images/photo3.jpg"  class="lazy" alt=""></li>10     </ul>11 </body>

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 }

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倾斜转换;

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
What is the difference between an HTML tag and an HTML attribute?What is the difference between an HTML tag and an HTML attribute?May 14, 2025 am 12:01 AM

HTMLtagsdefinethestructureofawebpage,whileattributesaddfunctionalityanddetails.1)Tagslike,,andoutlinethecontent'splacement.2)Attributessuchassrc,class,andstyleenhancetagsbyspecifyingimagesources,styling,andmore,improvingfunctionalityandappearance.

The Future of HTML: Evolution and TrendsThe Future of HTML: Evolution and TrendsMay 13, 2025 am 12:01 AM

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

Why are HTML attributes important for web development?Why are HTML attributes important for web development?May 12, 2025 am 12:01 AM

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

What is the purpose of the alt attribute? Why is it important?What is the purpose of the alt attribute? Why is it important?May 11, 2025 am 12:01 AM

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

HTML, CSS, and JavaScript: Examples and Practical ApplicationsHTML, CSS, and JavaScript: Examples and Practical ApplicationsMay 09, 2025 am 12:01 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

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

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

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.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools