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
HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 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: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 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 OverviewHTML vs. CSS vs. JavaScript: A Comparative OverviewApr 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: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 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.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

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

The Role of HTML: Structuring Web ContentThe Role of HTML: Structuring Web ContentApr 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

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)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

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

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor