html - 为什么我不能将文本放在一侧的平行四边形中

标签 html css

我有跨度,我用一侧创建了平行四边形,但我的文字不在跨度区域内,你知道什么是问题吗?

我也尝试通过添加 display:block 来解决这个问题,但没有用 http://jsfiddle.net/46be3tL4/5/

HTML

<span>LOREM IPSUM DOLOR</span>

CSS

span {
    display:block;
    border-top: 100px solid red;
    border-right: 50px solid transparent;
    height: 0;
    width: 100px;

}

最佳答案

您添加了边框,而不是背景。

您可以:

  • 将边框添加到伪元素而不是元素本身
  • 使用绝对定位从文档的正常流中移除伪元素,从而使其与内容重叠。
  • 使用负 z-index 将伪元素放置在内容下方。

span {
  display: block;
  position: relative;
  width: 200px;
  min-height: 40px;
}
span:before {
  content: '';
  position: absolute;
  z-index: -1;
  border-top: 40px solid red;
  border-right: 50px solid transparent;
  width: 100%;
}
<span>LOREM IPSUM DOLOR</span>

关于html - 为什么我不能将文本放在一侧的平行四边形中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31820432/

相关文章:

jquery - 使用 contains() 选择器和 Replace() 替换元素文本

jquery - 滚动时更改 Q Tip 的位置

javascript - 如何防止在 touchmove 和 mousemove 期间重定向 href?

javascript - 根据 ng-repeat angularjs 内部的控件验证禁用按钮

javascript - 当响应数据数组为空时,如何在 AngularJS ng Table 插件表中显示 "no data"消息

html - 证明内容 : space-between elements are not at the edges

css - 无法通过从父 &lt;footer&gt; 继承来覆盖 <a> 链接的蓝色

php - 在 img 内悬停时显示标题标签

html - 通过覆盖超链接使背景图像可点击?

html - div元素高度问题