仅从左侧移除阴影

时间:2016-09-09 18:56:38

标签: html css dropshadow box-shadow

我有一个:after按钮来创建一个箭头。我给按钮一个阴影框,并给:after一个投影,使:after看起来像是按钮的一部分。然而,在:after的左边缘有一小部分阴影,这使得它看起来与按钮断开连接。见图:

enter image description here

有没有办法摆脱左边缘的阴影?

出于某种原因箭头离开它下面的按钮但是没关系,只是试着阻止箭头沿着左边缘移动。

以下是代码:



#go-button {
  position:relative;
  border-radius: 6px;
  height: 64px;
  text-decoration: none;
  width: 80%;
  background-color: #00BFA5;
  padding: 12px;
  border: 0px solid #Fc4747;
  color: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: 200;
  z-index: 100;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); }

.bubble:after {
  content: '';
  position: absolute;
  border-style: solid;
  border-width: 15px 0 15px 24px;
  border-color: transparent #00BFA5;
  display: block;
  width: 0;
  z-index: 1;
  margin-top: -15px;
  right: -24px;
  top: 50%;
  -webkit-filter: drop-shadow(0px 4px 5px rgba(130, 130, 130, 0.7));
  filter: drop-shadow(0px 4px 5px rgba(130, 130, 130, 0.7));
  -ms-filter: "progid:DXImageTransform.Microsoft.Dropshadow(OffX=0, OffY=2, Color='#444')";
  filter: "progid:DXImageTransform.Microsoft.Dropshadow(OffX=0, OffY=2, Color='#444')"; }

<button id="go-button" type="submit" class="bubble">
  GO
</button>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:3)

你实际上想要使用drop-shadow,因为这是一个&#34;复杂的对象&#34;。将其移动到父元素;您会发现该阴影正确应用于after伪元素:

&#13;
&#13;
#go-button {
  position:relative;
  border-radius: 6px;
  height: 64px;
  text-decoration: none;
  width: 80%;
  background-color: #00BFA5;
  padding: 12px;
  border: 0px solid #Fc4747;
  color: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: 200;
  z-index: 100;
  -webkit-filter: drop-shadow(0px 4px 5px rgba(130, 130, 130, 0.7));
  filter: drop-shadow(0px 4px 5px rgba(130, 130, 130, 0.7));
  -ms-filter: "progid:DXImageTransform.Microsoft.Dropshadow(OffX=0, OffY=2, Color='#444')";
  filter: "progid:DXImageTransform.Microsoft.Dropshadow(OffX=0, OffY=2, Color='#444')";
}

.bubble:after {
  content: '';
  position: absolute;
  border-style: solid;
  border-width: 15px 0 15px 24px;
  border-color: transparent #00BFA5;
  display: block;
  width: 0;
  z-index: 1;
  margin-top: -15px;
  right: -24px;
  top: 50%;
}
&#13;
<button id="go-button" type="submit" class="bubble">
  GO
</button>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

如果您尚未使用:before作为元素,则可以始终使用其他伪元素隐藏阴影。另一个选择是偏移阴影,但这实际上只适用于小阴影。

第一个例子:

#go-button {
  position:relative;
  border-radius: 6px;
  height: 64px;
  text-decoration: none;
  width: 80%;
  background-color: #00BFA5;
  padding: 12px;
  border: 0px solid #Fc4747;
  color: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: 200;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
  z-index: 1;
}

.bubble:after {
  content: '';
  position: absolute;
  border-style: solid;
  border-width: 15px 0 15px 24px;
  border-color: transparent #00BFA5;
  display: block;
  width: 0;
  margin-top: -15px;
  right: -24px;
  top: 50%;
  -webkit-filter: drop-shadow(0px 4px 5px rgba(130, 130, 130, 0.7));
  filter: drop-shadow(0px 4px 5px rgba(130, 130, 130, 0.7));
  -ms-filter: "progid:DXImageTransform.Microsoft.Dropshadow(OffX=0, OffY=2, Color='#444')";
  filter: "progid:DXImageTransform.Microsoft.Dropshadow(OffX=0, OffY=2, Color='#444')";
}

.bubble:before {
  display: block;
  position: absolute;
  content: '';
  right: 0;
  top: 8px;
  height: 48px;
  width: 8px;
  background: #00BFA5;
  z-index: 2;
}
<button id="go-button" type="submit" class="bubble">
  GO
</button>

答案 2 :(得分:0)

box-shadow属性可能就是你想在这里使用的。阴影用于更复杂的对象或SVG。

您只需在:after元素周围应用更好的盒子阴影。

.bubble:after {
   box-sizing: border-box;    
   border: 1em solid #00BFA5;
   border-color: transparent transparent #00BFA5 #00BFA5;
   transform-origin: 0 0;
   transform: rotate(-135deg);
   display: block;
   width: 0;
   z-index: 1;
   margin-top: -15px;
   right: -250px;
   top: 50%;
   box-shadow: -3px 3px 3px 0 rgba(0, 0, 0, 0.4);
}

由于你没有提供一个工作小提琴我会留下旋转的调整等等,但一般的想法是你要在设置后设置盒子阴影的样式一个合适的边界&amp;边框颜色。

JsFiddle