search
HomeWeb Front-endHTML TutorialCSS2.1: 有意思的box-shadow非典型性应用场景_html/css_WEB-ITnose

最近对一些css很感兴趣。样式表的知识原理很容易被忽视,而且因为看似简单,所以更容易忘记。所以写下来咯~ box-shadow 这个东东,看起来好像很简单,就是阴影嘛!但是到底怎么用?是个神马规律?来来来,跟本猿一起学习一下。先看一个有意思的应用~ 这个月亮里面的阴影,是用box-shadow画的,很神奇吧。

box-shadow画圆.png

中间的一个圆,是靠下面两件事画的

  1. 绝对定位一个div (.moon:after)
  2. border-radius 和背景颜色设置
    <style type="text/css"> .moon { position: relative; } .moon:after {      content: '';      display: block;          position: absolute;      width: 50px;      height:50px;      border-radius: 50%;      background: rgba(0, 0, 0, 0.1);      //其他的小圆(用box-shadow)... }</style>

其他所有的圆 都是靠 第一个圆的 box-shadow,看代码:

<style type="text/css">     .moon { position: relative; }     .moon:after {          //其他的小圆(用box-shadow)...          box-shadow: 120px 80px 0 2px rgba(0, 0, 0, 0.1),                      100px -60px 0 -7px rgba(0, 0, 0, 0.1),                      -70px 40px 0 -14px rgba(0, 0, 0, 0.1),                        -20px -50px 0 -15px rgba(0, 0, 0, 0.1),                      -20px 120px 0 -15px rgba(0, 0, 0, 0.1),                      50px 50px 0 -15px rgba(0, 0, 0, 0.1);     }</style>

看出端倪了嘛?它们6个圆是阴影没错,但重点是它们是谁的阴影: 是第一个圆.moon:after的阴影!阴影是怎么一回事呢,阴影就是和偏移的,和原元素(谁的阴影)同样形状同样大小的一个东东,因为偏移,所以超过了原元素的部分,造成了阴影效果。那么box-shadow 后面的6句话,也就是对应着6个阴影,在这个场景中的表现也就是,6个圆。我们分析一下语法哈~

box-shadow: 120px 80px 0 2px rgba(0, 0, 0, 0.1),

前面两个参数120px 80px 是相对于原元素的定位,如果这两个参数是0px 0px那么刚好与原元素重合,没有偏移,也就没有阴影效果了。第三个参数0 ,就是模糊半径为0,也就是不模糊,这个值不能为负数。第四个参数是2px 就是 扩展半径,什么是扩展半径呢?就是如果这个值不设置的话,会默认为0,这时候,阴影就和原元素一模一样大,如果扩展半径为正数,数字越大,阴影部分就越大,可以认为是它相对于原元素多出来的大小程度。所以这个参数可以用来控制阴影圆的大小。最后一个参数颜色,这就不用讲啦,就是阴影的颜色啦~!

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
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.

HTML and Code: A Closer Look at the TerminologyHTML and Code: A Closer Look at the TerminologyApr 10, 2025 am 09:28 AM

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

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
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft