【问题标题】:Avoid line break between content and :after避免在内容和 :after 之间换行
【发布时间】:2015-04-01 15:36:07
【问题描述】:

我在 HTML 元素的内容和它的 :after 内容之间存在换行符问题。 这是一个可排序的表格,表格头部有一个小箭头。

你可以在这个小提琴http://jsfiddle.net/ceuwob93/或者这张图片上看到它:

显然我不想在箭头前面换行。

table {
    width: 300px;
}
thead {
    background-color: #ddd;
    border-bottom: 1px solid #bbb;
}
th.sort-down:after {
    content: '';
    float: right;
    margin-top: 7px;
    border-width: 0 4px 4px;
    border-style: solid;
    border-color: #404040 transparent;
}

【问题讨论】:

  • 您的表格单元格需要固定宽度。对我来说,您的代码没有中断单元格宽度为 400 像素和表格宽度为 800 像素的行。

标签: html css css-content


【解决方案1】:

http://jsfiddle.net/ceuwob93/1/

position:absolute !important;

只需将浮动更改为绝对位置。

【讨论】:

  • 是的,只是“绝对位置”。不需要!important
  • 这只是为了让小提琴知道我改变了那个值。
  • 从来没有必要。甚至不在小提琴中。我没有看到需要!important任何东西
【解决方案2】:

不要浮动伪元素,尝试绝对定位它。

table {
  width: 300px;
  vertical-align: top;
}
thead {
  background-color: #ddd;
  border-bottom: 1px solid #bbb;
}
.sort-down {
  position: relative;
  padding-right: 12px;
}
.sort-down:after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  border-width: 0 4px 4px;
  border-style: solid;
  border-color: #404040 transparent;
}
<table>
  <thead>
    <tr>
      <th>Column 1</th>
      <th class="sort-down">Problem</th>
      <th>Column 3</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Some long long long Text</td>
      <td>Yes</td>
      <td>Some other long long long text</td>
    </tr>
  </tbody>
</table>

【讨论】:

    【解决方案3】:

    您可以按照建议进行操作并将列固定宽度,或者如果您想要更灵活的方法,您可以为 :after 元素使用定位。

     table {
            width: 300px;
        }
        thead {
            background-color: #ddd;
            border-bottom: 1px solid #bbb;
        }
        .sort-down {
            padding-right: 1.5em;
            position:relative;
        }
        .sort-down:after {
            content: '';
            position:absolute;
            top:7px;
            right:5px;
            border-width: 0 4px 4px;
            border-style: solid;
            border-color: #404040 transparent;
        }
    <table>
      <thead>
        <tr>
          <th>Column 1</th>
          <th class="sort-down">Problem</th>
          <th>Column 3</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Some long long long Text</td>
          <td>Yes</td>
          <td>Some other long long long text</td>
        </tr>
      </tbody>
    </table>

    【讨论】:

      猜你喜欢
      • 2022-10-12
      • 2017-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多