【问题标题】:Text-decoration: line-through not working on IE?文字装饰:换行在 IE 上不起作用?
【发布时间】:2018-04-03 15:58:04
【问题描述】:

我有这个

.strike{
    text-decoration: line-through;
}

每次调用我的disable() 时,它都会禁用我的<select> 中的<option>s 并添加此类,但它不适用于IE。是的,我的<option>s 被禁用得很好,但 IE 上的文本装饰失败。解决方法是什么?谢谢。

编辑:我刚刚发现 text-decoration: line-through 在 Chrome 上也不起作用。

【问题讨论】:

  • 类添加到div是否成功
  • 可以添加一些代码示例吗?
  • @TomGerken:是的,我的课程成功添加到<option>,不知怎的,它看起来像这样<option disabled="disabled" class="strike">Option 1</option>

标签: html css internet-explorer


【解决方案1】:

样式select 元素的选项很少。这是一个support grid,它显示了您的可用选项(和限制)。

您最好以其他方式模拟“选择” (example),而不是尝试使用 CSS 设置选择表单控件的样式。

【讨论】:

    【解决方案2】:

    一般来说,option 元素在样式方面有很多限制,因为它们的渲染仍然主要基于系统中的内置例程,而这些例程通常无法通过 CSS 控制。 Overstriking 通常不起作用,因为您可以使用简单的静态示例<select><option style="text-decoration: line-through">Hello world</select> 进行测试。 (出于好奇,Firefox 使用 line through,但不是在初始状态下最初选择的选项上。)

    考虑使用替代方法。如果无法选择一个选项,为什么不直接删除它? (我的意思是用 JavaScript 删除元素。用 CSS 隐藏它效果不好。)

    或者,将其disabled 属性设置为true。这将阻止它被选中,并在流行的浏览器上以灰色文本显示。

    【讨论】:

      【解决方案3】:

      我的问题是 text-decoration: line-through;不能在 IE 中工作。我使用简写在单个声明中设置一个或多个单独的文本装饰值(例如 text-decoration: line-through dashed blue)。我发现它还不支持。 https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration

      如果您的下划线/穿线需要另一种颜色,请使用额外的 span 元素。

      <span style="color:red; text-decoration: line-through;"><span style="color: blue; text-decoration: none">Try this!</span></span>

      不确定这是否会对您的情况有所帮助。

      【讨论】:

        【解决方案4】:

        您可能会变得棘手,并为文本 div 添加一个像素的背景。这至少是面向未来的并且适用于所有浏览器。

        【讨论】:

          【解决方案5】:

          在这里,试试这个:

          <p>Bla bla bla <span class="strike">RAAAAAA!</span></p>
          

          和: ​

          span.strike{
              position: relative;
              text-align: center;
              z-index: 1;    
          }
          
          span.strike:before {
              border-top: 1px solid #000;
              content:"";
              width: 100%;
              position: absolute;
              top: 50%; 
              z-index: -1;
          }
          

          编辑:哦,这是一个选择。没关系。

          【讨论】:

            【解决方案6】:

            来,试试这个

            <select>
                <option selected> Size - </option>
                <option class="disabledoption">Short Option</option>
                <option class="disabledoption">This Is </option>
                <option class="disabledoption">dssdsd Is </option>
                <option class="disabledoption">yes </option>
                <option class=>ertyu </option>
                <option class=>gsdgsdf </option>
            </select>
            
            <script type="text/javascript">
            jQuery(document).ready(function() {
                uni = '\u0336';
                jQuery('.disabledoption', this).each(function(index, element) {
                    uni = '\u0336';
                    var result = strikeString(jQuery(this).html(), uni);
                    jQuery(this).html(result);
                });
                });
                function strikeString(str, strikeKind) {
                    var result = '';
                    for (var i = 0; i < str.length; i++) {
                        var c = str.charAt(i);
                        var r = c+strikeKind;
                        result += r;
                    }
                return result;
            }
            </script>
            

            【讨论】:

            • 欢迎来到 Stack Overflow!这根本不符合提出问题的人的要求。这实际上改变了文本。问题是关于应用strikethrough 样式。 完全不同的东西。您应该针对问题中的问题专门调整每个答案。
            猜你喜欢
            • 2011-12-28
            • 1970-01-01
            • 1970-01-01
            • 2012-07-10
            • 2017-06-20
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多