


How to add shadow effect to images with css? Two ways to add shadows to pictures (code examples)
css can achieve many picture effects, and picture shadow effect is one of them. So how to add shadow effect to pictures in css? This article will introduce to you how to use css to add shadows to images (with code), and let you know the two methods of adding shadows to images with css. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
First let’s take a look at how to add shadow effects to images using cssThe first method: setting the box-shadow attribute, let’s take a look at the implementation of the box-shadow attribute through a simple code example method.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>css 图片阴影--box-shadow属性</title> <style> .demo{ width: 400px; height: 300px; margin: 50px auto; } .demo img{ box-shadow: 10px 10px 10px rgba(0,0,0,.5); /*考虑浏览器兼容性*/ -moz-box-shadow: 10px 10px 10px rgba(0,0,0,.5); -webkit-box-shadow: 10px 10px 10px rgba(0,0,0,.5); } </style> </head> <body> <div class="demo"> <img src="/static/imghwm/default1.png" data-src="https://img.php.cn//upload/image/168/638/459/1539834402154297.jpg?x-oss-process=image/resize,p_40" class="lazy" / alt="How to add shadow effect to images with css? Two ways to add shadows to pictures (code examples)" > </div> </body> </html>
Rendering:
#The box-shadow attribute is not very simple to set the image shadow. Let’s take a look at how to set the box-shadow attribute. of:
box-shadow: h-shadow v-shadow blur spread color inset;
h-shadow: Required value that defines the position of the horizontal shadow. Negative values are allowed.
v-shadow: A required value that defines the position of the vertical shadow. Negative values are allowed.
blur: Optional setting value, defining the blur distance.
spread: Optional setting value that defines the size of the shadow.
color: Optional set value that defines the color of the shadow. If no value is set, the color value is based on browser display. It is recommended to set it.
inset: The value of the optional setting. After setting, the outer shadow (outset) can be changed to the inner shadow.
Next let’s take a look at how to add shadow effects to images using cssThe second method: use the filter attribute of css3 -----filter attribute to set the shadow of the image.
You can set filter:drop-shadow(); to add a shadow to the image. Let’s see how to implement it through a simple code example.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>css 图片阴影--box-shadow属性</title> <style> .demo{ width: 400px; height: 300px; margin: 50px auto; } .demo img{ -webkit-filter: drop-shadow(10px 10px 10px rgba(0,0,0,.5)); /*考虑浏览器兼容性:兼容 Chrome, Safari, Opera */ filter: drop-shadow(10px 10px 10px rgba(0,0,0,.5)); } </style> </head> <body> <div class="demo"> <img src="/static/imghwm/default1.png" data-src="https://img.php.cn//upload/image/763/722/108/1539841316558232.jpg?x-oss-process=image/resize,p_40" class="lazy" / alt="How to add shadow effect to images with css? Two ways to add shadows to pictures (code examples)" > </div> </body> </html>
Rendering:
Description:
filter:drop-shadow(h-shadow v-shadow blur spread color);
h-shadow: Set the horizontal offset of the shadow; negative values are allowed , negative values will cause the shadow to appear on the left side of the element.
v-shadow: Set the vertical offset of the shadow; negative values are allowed, and negative values will cause the shadow to appear above the element.
blur: Set the blur of the shadow. The larger the value, the blurrier the shadow will be. The shadow will become larger and lighter; negative values are not allowed. If not set, the default is 0 (the boundary of the shadow is very small). sharp).
spread: Set the size of the shadow. Positive values will cause the shadow to expand and become larger, while negative values will cause the shadow to shrink. If not set, the default is 0 (the shadow will be the same size as the element).
Note: Spread is not supported in Webkit and some other browsers, and it will not render if added.
color: Set the shadow color; if not set, the color value is based on the browser, it is recommended to set the color.
Summary: The above is the complete content of the two methods of adding shadows to images with CSS. I hope it will be helpful to everyone's learning. For more related tutorials, please visit CSS3 Video Tutorial, Html5 Video Tutorial, bootstrap Video Tutorial!
The above is the detailed content of How to add shadow effect to images with css? Two ways to add shadows to pictures (code examples). For more information, please follow other related articles on the PHP Chinese website!

In this week's roundup: Firefox gains locksmith-like powers, Samsung's Galaxy Store starts supporting Progressive Web Apps, CSS Subgrid is shipping in Firefox

In this week's roundup: Internet Explorer finds its way into Edge, Google Search Console touts a new speed report, and Firefox gives Facebook's notification

You’re probably already at least a little familiar with CSS variables. If not, here’s a two-second overview: they are really called custom properties, you set

Building websites is programming. Writing HTML and CSS is programming. I am a programmer, and if you're here, reading CSS-Tricks, chances are you're a

Here's what I'd like you to know upfront: this is a hard problem. If you've landed here because you're hoping to be pointed at a tool you can run that tells

Picture-in-Picture made its first appearance on the web in the Safari browser with the release of macOS Sierra in 2016. It made it possible for a user to pop

Gatsby does a great job processing and handling images. For example, it helps you save time with image optimization because you don’t have to manually

I learned something about percentage-based (%) padding today that I had totally wrong in my head! I always thought that percentage padding was based on the


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

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.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment