无法显示:在具有背景的div上方的元素之后

时间:2016-11-22 21:31:56

标签: html css css3

我正在尝试为表单添加一些样式,并且我在使用:after伪元素在div / input下创建阴影时遇到问题。

当我将div /输入直接放在它上面时,它按预期工作。但是,当我尝试将其放在具有背景颜色的另一个DIV中时,伪元素永远不会显示。

jsfiddle



div.home-header-input {
  width: 40%;
  background-color: #fff;
  vertical-align: top;
  height: 100px;
  border-radius: 5px;
  position: relative;
}

div.home-header-input:after {
  content: "";
  display: block;
  border-bottom: 12px solid #e1e1dc;
  position: absolute;
  z-index: -1;
  bottom: -4px;
  width: 100%;
  left: 0;
  right: 0;
  border-bottom-left-radius: 5px;
  border-bottom-right-radius: 5px;
}

input.home-header-input {
  margin: 34px 24px 34px 22px;
  color: #324b5a;
  border: none;
  padding: 0;
  width: 61%;
  background: transparent;
  outline: 0;
  line-height: 1;
  font-size: 1.4em;
}

.i-will-break-everything {
  margin: 30px 0;
  padding: 30px;
  width: 100%;
  height: 400px;
  background: #fff39b;
}

<div class="home-header-input">
  <input type="text" value="" placeholder="Type your text here" class="home-header-input">
</div>

<div class="i-will-break-everything">
  <div class="home-header-input">
    <input type="text" value="" placeholder="Type your text here" class="home-header-input">
  </div>
</div>
&#13;
&#13;
&#13;

你能帮我弄清楚出了什么问题吗?

1 个答案:

答案 0 :(得分:3)

div.home-header-input {
  width: 40%;
  background-color: #fff;
  vertical-align: top;
  height: 100px;
  border-radius: 5px;
  position: relative;
}

div.home-header-input:after {
  content: "";
  display: block;
  border-bottom: 12px solid #e1e1dc;
  position: absolute;
  z-index: -1;
  bottom: -4px;
  width: 100%;
  left: 0;
  right: 0;
  border-bottom-left-radius: 5px;
  border-bottom-right-radius: 5px;
}

input.home-header-input {
  margin: 34px 24px 34px 22px;
  color: #324b5a;
  border: none;
  padding: 0;
  width: 61%;
  background: transparent;
  outline: 0;
  line-height: 1;
  font-size: 1.4em;
}

.i-will-break-everything {
  margin: 30px 0;
  padding: 30px;
  width: 100%;
  height: 400px;
  background: #fff39b;
  position: absolute;
  z-index: -2;
}
<div class="home-header-input">
  <input type="text" value="" placeholder="Type your text here" class="home-header-input">
</div>

<div class="i-will-break-everything">
  <div class="home-header-input">
    <input type="text" value="" placeholder="Type your text here" class="home-header-input">
  </div>
</div>

Fiddle