简体   繁体   English

如何使用阴影创建实心边框?

[英]How can I use shadow to create a solid border?

I am trying to add a border using box-shadow inset , because of the condition i am not able to use the border-box on one of the a element.我正在尝试使用box-shadow inset添加边框,因为我无法在a元素之一上使用border-box But not getting.但没有得到。 any help?有什么帮助吗?

 .parent{ background: #FFF; padding:5rem; box-shadow: inset 1px 1px 0px 2px rgba(0,0,0,1); }
 <div class="parent"></div>

If you want equal border-width on all sides - just remove offset-x and offset-y :如果您希望所有边的边框宽度相等 - 只需删除offset-xoffset-y

 .parent{ background: #c9c9c9; padding:5rem; box-shadow: inset 0 0 0 2px rgba(0,0,0,1); }
 <div class="parent"></div>

Change the horizontal and vertical offset (value) of the shadow to 0px such as:将阴影的水平和垂直偏移(值)更改为 0px 例如:

   box-shadow: inset 0px 0px 0px 2px rgba(0,0,0,1);

 .parent{ background: #FFF; padding:5rem; box-shadow: inset 0px 0px 0px 2px rgba(0,0,0,1); }
 <div class="parent"></div>

In case you cannot use the border property here is different techniques that allow you to create a border for your element:如果您不能在此处使用border属性,可以使用不同的技术为您的元素创建边框:

Using outline使用大纲

 .parent{ background: #FFF; padding:5rem; outline:2px solid rgba(0,0,0,1); }
 <div class="parent"></div>

Using Box-shadow使用 Box-shadow

 .parent{ background: #FFF; padding:5rem; margin:5px; box-shadow:0 0 0 2px rgba(0,0,0,1); } .parent.inset { box-shadow:inset 0 0 0 2px rgba(0,0,0,1); }
 <div class="parent"></div> <div class="parent inset"></div>

Using gradient使用渐变

 .parent{ background: #FFF; padding:5rem; margin:5px; background: linear-gradient(#000,#000) top/100% 2px, linear-gradient(#000,#000) bottom/100% 2px, linear-gradient(#000,#000) left/2px 100%, linear-gradient(#000,#000) right/2px 100%; background-repeat:no-repeat; }
 <div class="parent"></div>

Another way with gradient if you want to have a background-color :如果您想要background-color则使用渐变的另一种方法:

 .parent{ background: #FFF; padding:5rem; margin:5px; background: linear-gradient(pink,pink) center/calc(100% - 4px) calc(100% - 4px), linear-gradient(#000,#000); background-repeat:no-repeat; }
 <div class="parent"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM