如何改变线的穿透高度

时间:2014-09-10 08:38:18

标签: html css css3

昨天和一位朋友讨论了关于罢工的线路变化高度。 今天在documentation CSS上搜索说:

The HTML Strikethrough Element (<s>) renders text with a strikethrough, or a line through it.
Use the <s> element to represent things that are no longer relevant or no longer accurate. 
However, <s> is not appropriate when indicating document edits; 
for that, use the <del> and <ins> elements, as appropriate.

似乎<s>接受CSS的所有引用,但不接受高度函数。

CSS:

s {
    color: red;
    height: 120px
  }

HTML:

<br /><br />
<s >Strikethrough</s>

有一个更简单的demo on JSFIDDLE,你看到它不会改变线的高度......

还有一种替代解决方案,或者我错了CSS?

使用图片进行说明

enter image description here

4 个答案:

答案 0 :(得分:2)

我之前想要这样做并提出这个:

<span class="strike">
    <span class="through"></span>
    Strikethrough
</span>

.strike {
    position:relative;
    color:red;
}

.strike .through {
    position:absolute;
    left:0;
    width:100%;
    height:1px;
    background: red;
    /* position of strike through */
    top:50%;
}

JS Fiddle here

如果你想要多次攻击,可以使用以下内容:

JS Fiddle - multi strikes

答案 1 :(得分:2)

我认为处理此问题的最佳方法是使用伪元素来模拟所需的行为。

 s {
    color: red;
    display: inline-block;
    text-decoration: none;
    position: relative;
  }
s:after {
    content: '';
    display: block;
    width: 100%;
    height: 50%;
    position: absolute;
    top: 0;
    left: 0;
    border-bottom: 3px solid;
}

边框继承文字颜色,您可以完全控制样式,包括悬停效果。

JS Fiddle here

答案 2 :(得分:1)

这是我的替代版本。

s {
        color: red;
        position: relative;
        text-decoration: none;
      }

s:after {
    position: absolute;
    left: 0;
    right: 0;
    top: -10px;
    content: " ";
    background: red;
    height: 1px;
}

<强> JSFiddle demo

答案 3 :(得分:1)

试试这个

  s {
     color: red;
     text-decoration: none;
     background-image: linear-gradient(transparent 7px,#cc1f1f 7px,#cc1f1f 12px,transparent 9px);
     height: 100px
  }