【问题标题】:stop :before and element overlapptingstop :before 和元素重叠
【发布时间】:2017-11-20 17:33:02
【问题描述】:

我有一个 css 类,它附加了一个伪 :before 类。 :before 类只是一个边框,但它与文本重叠。我试过填充,但它仍然重叠。这是css代码

 .chevron {
        width: auto;
        min-width: 100px;
        position: relative;
        background: #d1dce6;
        text-overflow: ellipsis;
        height: 40px;
        max-height: 40px;
    }
    .chevron:before  {
        content: "";
        position: absolute;
        left: 0;
        bottom: 0;
        width: 0;
        height: 0;

        border-left: 20px solid white;
        border-top: 20px solid transparent;
        border-bottom: 20px solid transparent;
    }

如何在白色边框 (:before) 和文本之间留出一些空间

编辑 1:将 css 类应用于元素。向左填充不起作用。

 <th class="chevron" v-for="p in joinTo">{{p.description.trunc(30)}}</th>

【问题讨论】:

  • 你能给小提琴吗?
  • @DmytroLishtvan 如果您了解问题所在,则无需提琴。 :)
  • 试试 padding -left 30 or 40 px
  • 我想看看这个 CSS 附带的 HTML 代码 :)
  • 更新的 sn-p

标签: css


【解决方案1】:

只需在父元素中添加一些填充:

.chevron {
    width: auto;
    min-width: 100px;
    position: relative;
    background: #d1dce6;
    text-overflow: ellipsis;
    height: 40px;
    max-height: 40px;
    /* Add this line: */
    padding-left: 50px;
}

提示:由于您已经拥有left: 0,因此您无需担心左对齐问题。

此外,正如 cmets 中所指出的,如果您不希望整体尺寸因填充而增加,您可以使用两者之一:

padding-left: 50px;
box-sizing: border-box;
text-indent: 50px;

【讨论】:

  • 或者text-indent: 50px;,如果你不想增加元素的大小。
  • @Cons7an7ine 好一个。您也可以使用box-sizing: border-box,以便它提供相同的输出。好一个人。
  • @Abhi.Net 可能是因为其他样式覆盖了它?
【解决方案2】:

您需要为父元素添加填充

 .chevron {
        width: auto;
        min-width: 100px;
        position: relative;
        background: #d1dce6;
        text-overflow: ellipsis;
        height: 40px;
        max-height: 40px;
        padding-left: 40px;
    }
    .chevron:before  {
        content: "";
        position: absolute;
        left: 0;
        bottom: 0;
        width: 0;
        height: 0;

        border-left: 20px solid white;
        border-top: 20px solid transparent;
        border-bottom: 20px solid transparent;
    }
<table>
  <thead>
      <tr>
          <th class="chevron">sdsdsd</th>
          <th class="chevron">sdsdsd</th>
          <th class="chevron">sdsdsd</th>
          <th class="chevron">sdsdsd</th>
          <th class="chevron">sdsdsd</th>
      </tr>
  </thead>
</table>

【讨论】:

  • 应该再添加一件事......该类应用于第一个元素。我试过 padding-left ,不行。
  • @Abhi.Net 添加了表格。这就是为什么我想要你的小提琴 - 因为一切正常)尝试添加 !important 到你的填充
猜你喜欢
  • 2012-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-28
  • 2012-12-01
  • 2013-09-03
  • 1970-01-01
  • 2018-10-06
相关资源
最近更新 更多