为什么背景颜色:白色;不起作用?

时间:2017-04-09 09:32:16

标签: javascript jquery html css

这是我的代码:

<span>test</span>
<div></div>
{{1}}

如您所见,该黑线仍在文字上。我为文本设置了白色背景颜色。为什么不出现?

我想在文字的边缘剪掉那条黑线。换句话说,该行应该包围文本。

3 个答案:

答案 0 :(得分:3)

span需要的位置,即position: relative z-index工作

&#13;
&#13;
body{
  text-align: center;
}

span{
  position: relative;
  background-color: white;
  z-index: 2;
}

div{
  border-top: 1px solid;
  position: absolute;
  width: 100%;
  margin-top: -8px;
  z-index: 1;
}
&#13;
<span>test</span>
<div></div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

position:relative添加到范围。

&#13;
&#13;
body{
  text-align: center;
}

span{
  position:relative;
  background-color: white;
  z-index: 2;
}

div{
  border-top: 1px solid;
  position: absolute;
  width: 100%;
  margin-top: -8px;
  z-index: 1;
}
&#13;
<span>test</span>
<div></div>
&#13;
&#13;
&#13;

答案 2 :(得分:-1)

你的身体标签在哪里?

&#13;
&#13;
body{
  text-align: center;
}

span{
  background-color: red;
  z-index: 2;
}

div{
  border-top: 1px solid;
  position: absolute;
  width: 100%;
  margin-top: -8px;
  z-index: 1;
}
&#13;
<body>
    <span>test</span>
    <div></div>
</body>
&#13;
&#13;
&#13;

相关问题