代码之家  ›  专栏  ›  技术社区  ›  user2024080

我可以添加像边框一样的插入阴影吗?

  •  0
  • user2024080  · 技术社区  · 7 年前

    我正在尝试使用添加边框 box-shadow inset ,因为我不能使用 border-box 在其中一个 a 元素。但没有得到。有什么帮助吗?

    .parent{
      background: #FFF;
      padding:5rem;
      box-shadow: inset 1px 1px 0px 2px rgba(0,0,0,1);
    }
    <div class="parent"></div>
    3 回复  |  直到 7 年前
        1
  •  1
  •   stemon    7 年前

    将阴影的水平和垂直偏移(值)更改为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>
        2
  •  1
  •   fen1x    7 年前

    如果您希望所有边的边框宽度相等-只需删除 offset-x offset-y :

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

    如果您不能使用 border 属性以下是允许您为元素创建边框的不同技术:

    使用大纲

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

    使用方框阴影

    .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>

    使用渐变

    .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=“父级”></DIV>

    如果你想有一个 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=“父级”></DIV>