CSS2.1: 有意思的box-shadow非典型性应用场景_html/css_WEB-ITnose
最近对一些css很感兴趣。样式表的知识原理很容易被忽视,而且因为看似简单,所以更容易忘记。所以写下来咯~ box-shadow 这个东东,看起来好像很简单,就是阴影嘛!但是到底怎么用?是个神马规律?来来来,跟本猿一起学习一下。先看一个有意思的应用~ 这个月亮里面的阴影,是用box-shadow画的,很神奇吧。
box-shadow画圆.png
中间的一个圆,是靠下面两件事画的
- 绝对定位一个div (.moon:after)
- 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>
Copy after login
而 其他所有的圆 都是靠 第一个圆的 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,这时候,阴影就和原元素一模一样大,如果扩展半径为正数,数字越大,阴影部分就越大,可以认为是它相对于原元素多出来的大小程度。所以这个参数可以用来控制阴影圆的大小。最后一个参数颜色,这就不用讲啦,就是阴影的颜色啦~!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

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.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

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.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.
