How to create a box shadow that is just an outline?

跟風遠走 提交于 2019-12-24 01:57:41

问题


How would I be able to create something like the link above with html and css? Every time I try to make it into a thin line like (box-shadow: 10px 10px 1px #FFE600;) it disappears. Would I just need to create a separate div for this?

Here's my curent code: HTML

<img src="../images/about.jpg" alt="Yonge and Dundas Street" class="pageimg">

CSS

.pageimg {
    width: 37%;
    float: right;
    margin-left: 100px;
    box-shadow: 10px 10px #FFE600;
}

回答1:


Use multiple box-shadows:

img {
  box-shadow:
   12px 8px 0 0px white,
   14px 6px 0 0px yellow,
   14px 10px 0 0px yellow,
   10px 10px 0 0px yellow;
}
<img src="https://picsum.photos/200/200?image=1069">



回答2:


You could also rather use pseudo elements. I do recommend keeping images in containers as it makes working with them easier. It would look something like this.

.image-container{
    position: relative;
    display: inline-block;
}
.image-container::before{
    content: '';
    position: absolute; 
    border: solid 1px yellow;
    width: 100%;
    height: 100%;
    left: 14px; /* This will be your box shadow x-offset; */
    top: 14px; /* This will be your box shadow y-offset; */
    z-index: 0;
}

and then your html

<div class="image-container">    
    <img src="../images/about.jpg" alt="Yonge and Dundas Street" class="pageimg">
</img>


来源:https://stackoverflow.com/questions/53093169/how-to-create-a-box-shadow-that-is-just-an-outline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!