如何在一个div元素周围设置图像的阴影效果?

huangapple go评论85阅读模式
英文:

How do I set this shadow effect in an image around a div element?

问题

这是我想要的图像:

<a href="https://i.stack.imgur.com/wRSLl.png"><img src="https://i.stack.imgur.com/wRSLl.png"></a>

我想要在一个元素周围创建类似的浅灰色阴影效果;
我尝试设置与边框相关的CSS属性,但效果不理想。

我的想法是使用CSS的渐变效果,但我对CSS的渐变不是特别熟悉。

英文:

Here's an image of what I want:

<a href="https://i.stack.imgur.com/wRSLl.png"><img src="https://i.stack.imgur.com/wRSLl.png"></a>

I want to have a similar light gray shadow effect around an element;
I tried setting CSS properties related to the border, but it didn't work out.

My idea is to use the gradient effect of css, but I am not particularly familiar with the gradient of css.

答案1

得分: 1

你可以使用 box-shadow CSS 属性:

/* 水平偏移量 | 垂直偏移量 | 模糊半径 | 扩展半径 | 颜色 */
box-shadow: 0 0.25rem 1rem 0.25rem rgba(0, 0, 0, 0.05);
<button class="my-btn">待评价</button>
英文:

You can use the box-shadow CSS property:

/* offset-x | offset-y | blur-radius | spread-radius | color */
box-shadow: 0 0.25rem 1rem 0.25rem rgba(0, 0, 0, 0.05);

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

body { padding: 1em; }

.my-btn {
  background: #FFF;
  padding: 0.25em 1em;
  border: none;
  border-radius: 1.5em;
  box-shadow: 0 0.25rem 1rem 0.25rem rgba(0, 0, 0, 0.05);
  font-size: 2em;
}

.my-btn:hover {
  cursor: pointer;
  box-shadow: 0 0.25rem 1rem 0.25rem rgba(0, 0, 0, 0.15);
}

.my-btn:active {
  background: #222;
  color: #EEE;
  box-shadow: 0 0.25rem 1rem 0.25rem rgba(0, 0, 0, 0.5);
}

<!-- language: lang-html -->

&lt;button class=&quot;my-btn&quot;&gt;待评价&lt;/button&gt;

<!-- end snippet -->

答案2

得分: 0

尝试这个:
Css:

.btn {
    width: 200px;
    height: 150px;
    border: none;
    outline: none;
    box-shadow: 2px 2px 12px 2px #efefef;
    border-radius: 8px;
}

Html:

<div class="btn">你好</div>
英文:

Try this:
Css:

.btn {
width:200px;
height:150px;
border:none;
outline:none;
box-shadow:2px 2px 12px 2px #efefef;
border-radius:8px;
}

Html:

&lt;div class=&quot;btn&quot;&gt;Hello&lt;/div&gt;

huangapple
  • 本文由 发表于 2023年7月18日 00:30:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76706452.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定