Box-Shadow超过其他元素

时间:2017-02-03 08:21:44

标签: html css css3

我有这段代码而且icon <div> box-shadow已超过icon-button我该怎么办?

* {
  box-sizing: border-box;
}

.edit-button {
  padding: 8px 12px;
  width: 500px;
  margin: 50px auto;
}

.icon-button {
  position: relative;
  background: #fcac22;
  border-top: 1px solid #f9aa22;
  border-right: none;
  border-bottom: 3px solid #e29a1f;
  border-left: 1px solid #f7a921;
  color: #fff;
  border-radius: 2px 0 0 3px;
  outline: none;
  text-align: center;
  width: calc(100% - 36px);
  height: 69px;
  line-height: 18px;
  padding: 19px;
  text-shadow: 0px 0px .1px #fff;
  z-index: 1;
  -webkit-box-shadow: -1px 2px 19px 1px rgba(0, 0, 0, 0.3);
  -moz-box-shadow: -1px 2px 19px 1px rgba(0, 0, 0, 0.3);
  box-shadow: -1px 2px 19px 1px rgba(0, 0, 0, 0.3);
  font-family: arial;
  font-size: 16px;
  font-weight: 400;
}
.icon-button .icon {
  position: absolute;
  width: 32px;
  height: 69px;
  display: inline-block;
  right: -36px;
  top: -1px;
  background: #fcac22;
  border-top: 1px solid #f9aa22;
  border-right: 1px solid #f7a921;
  border-bottom: 3px solid #e29a1f;
  border-left: none;
  border-radius: 0 2px 3px 0;
  z-index: 0;
  -webkit-box-shadow: -1px 2px 19px 1px rgba(0, 0, 0, 0.3);
  -moz-box-shadow: -1px 2px 19px 1px rgba(0, 0, 0, 0.3);
  box-shadow: -1px 2px 19px 1px rgba(0, 0, 0, 0.3);
}
.icon-button .icon-circle {
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 100%;
  margin: 23px auto;
  color: #e29a1f;
  font-size: 13px;
  line-height: 29px;
  text-shadow: none;
}
<div class="edit-button">
  <button class="icon-button">
    Shop
    <br>MYMARKET.GE
    <div class="icon">
      <div class="icon-circle"><i class="ic-link"></i>
      </div>
    </div>
  </button>
</div>

这是问题

enter image description here

2 个答案:

答案 0 :(得分:2)

您可以在icon-button

上使用伪
.icon-button::before {
  content: '';
  position: absolute;
  width: 26px;
  height: 69px;
  right: -40px;
  top: -1px;
  background: #fcac22;
  border-radius: 0 2px 3px 0;
  z-index: -1;
  -webkit-box-shadow: -1px 2px 19px 1px rgba(0, 0, 0, 0.3);
  -moz-box-shadow: -1px 2px 19px 1px rgba(0, 0, 0, 0.3);
  box-shadow: -1px 2px 19px 1px rgba(0, 0, 0, 0.3);
}

样品

* {
  box-sizing: border-box;
}

.edit-button {
  padding: 8px 12px;
  width: 500px;
  margin: 50px auto;
}

.icon-button {
  position: relative;
  background: #fcac22;
  border-top: 1px solid #f9aa22;
  border-right: none;
  border-bottom: 3px solid #e29a1f;
  border-left: 1px solid #f7a921;
  color: #fff;
  border-radius: 2px 0 0 3px;
  outline: none;
  text-align: center;
  width: calc(100% - 36px);
  height: 69px;
  line-height: 18px;
  padding: 19px;
  text-shadow: 0px 0px .1px #fff;
  z-index: 1;
  -webkit-box-shadow: -1px 2px 19px 1px rgba(0, 0, 0, 0.3);
  -moz-box-shadow: -1px 2px 19px 1px rgba(0, 0, 0, 0.3);
  box-shadow: -1px 2px 19px 1px rgba(0, 0, 0, 0.3);
  font-family: arial;
  font-size: 16px;
  font-weight: 400;
}
.icon-button::before {
  content: '';
  position: absolute;
  width: 26px;
  height: 69px;
  right: -38px;
  top: -1px;
  background: #fcac22;
  border-radius: 0 2px 3px 0;
  -webkit-box-shadow: -1px 2px 19px 1px rgba(0, 0, 0, 0.3);
  -moz-box-shadow: -1px 2px 19px 1px rgba(0, 0, 0, 0.3);
  box-shadow: -1px 2px 19px 1px rgba(0, 0, 0, 0.3);
}

.icon-button .icon {
  position: absolute;
  width: 32px;
  height: 69px;
  display: inline-block;
  right: -36px;
  top: -1px;
  background: #fcac22;
  border-top: 1px solid #f9aa22;
  border-right: 1px solid #f7a921;
  border-bottom: 3px solid #e29a1f;
  border-left: none;
  border-radius: 0 2px 3px 0;
  z-index: 0;
}
.icon-button .icon-circle {
  display: inline-block;
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 100%;
  margin: 23px auto;  
  color: #e29a1f;
  font-size: 13px;
  line-height: 29px;
  text-shadow: none;
}
<div class="edit-button">
  <button class="icon-button">
    Shop
    <br>MYMARKET.GE
    <span class="icon">
      <span class="icon-circle"><i class="ic-link"></i>
      </span>
    </span>
  </button>
</div>

div元素中不允许使用John Bupitbutton元素指出的注释,因此我在上面的代码中进行了必要的更改,替换为{{1 } div并将span添加到display: inline-block规则

答案 1 :(得分:1)

是否可以将.icon-button .icon box-shadow负值更改为正值,如

.icon-button .icon{ box-shadow: 5px 2px 19px 1px rgba(0, 0, 0, 0.3);}

不完全5px它取决于您(任何正数)