【问题标题】:Text decoration line through css does not work on Safari with my "completed" class通过 css 的文本装饰线在我的“已完成”类的 Safari 上不起作用
【发布时间】:2025-11-30 00:35:01
【问题描述】:

我一直在多台设备上测试我的应用程序,但发现我的一种 css 样式不适用于 Safari,尤其是我的 iPhone 和 iPad。我正在使用 Angular 制作一个待办事项应用程序,并且希望在项目标记为已完成时用红线划掉文本。

如果我创建一个新的段落元素并将其赋予类 test 并应用下面的 css,则样式可以正常工作。

例如,这条线被划掉了

<p class="test">testing 3</p>

有了这个css

.test {
  text-decoration: line-through;
  -webkit-text-decoration-line: line-through;
  color: red;
}

但是,这个 html 没有被划掉

  <li *ngFor="let list of lists" [class.completed]="list.completed" class="list-lines">
    <table>
      <tr>
        <td class="check">
          <input id='checked' *ngIf="list.completed === false" type="checkbox" (click)='isChecked(list)'>
          <input id='checked' *ngIf="list.completed === true" type="checkbox" (click)='isChecked(list)' checked>
        </td>
        <td class="todoBox">
          <span class="todo" (click)="isChecked(list)">{{list.item}}</span>
        </td>
        <td>
          <button id="delOneButton" class="btn btn-danger" (click)="delOne(list)" [hidden]="!list.completed">Delete</button>
        </td>
      </tr>
    </table>
  </li>

当这个 css 应用到我的班级时完成。就像我说的那样,它在我的 Chrome 桌面上运行良好,但在我的 Safari 上却不行。什么给了??

.completed {
  text-decoration: line-through;
  -webkit-text-decoration-line: line-through;
  color: red;
}

我找到了这个文档,但似乎找不到关于通过文本装饰的移动 css 语法的任何其他内容。有谁知道我在哪里可以找到语法?

【问题讨论】:

    标签: css safari mobile-safari


    【解决方案1】:

    看起来我需要更具体地使用 webkit css。而不是

    .completed {
      text-decoration: line-through;
      -webkit-text-decoration-line: line-through;
      color: red;
    }
    

    我需要写

    .completed .todoBox .todo {
      text-decoration-line: line-through;
      -webkit-text-decoration-line: line-through;
      text-decoration-color: red;
      -webkit-text-decoration-color: red;
    }
    

    【讨论】:

      【解决方案2】:

      我们去-webkit-text-decoration-line: line-through; 了解更多关于此的信息,您可以阅读here。希望对您有所帮助:)

      【讨论】:

      • 我希望这会奏效。它没有用。不知道是不是因为手机版和桌面版的兼容性不一样?? :(
      • 好的,它确实有效。但不是我想要的方式。你能检查我的代码,看看有什么问题吗?我将添加我的html代码并进一步解释。
      • 一切都很好,也可以在我的 iPhone 上使用。看到这个小提琴,告诉我你看到了什么jsfiddle.net/nyrq2x8c/5
      • 是的,我可以看到十字架。我修改了我的问题,因为它有效。你能再回顾一下,看看你能不能帮到我?
      • 尝试为特定浏览器设置样式,safari: `_::-webkit-full-page-media, _:future, :root .yourclass {}` 我猜是 safari bug
      【解决方案3】:

      这在 Safari 和 Google Chrome 中对我有用。

      .test{
           text-decoration: line-through red;
           -webkit-text-decoration: line-through red;
      

      }

      【讨论】:

        最近更新 更多