开发者

Strike tag issue in firefox versus ie/chrome

开发者 https://www.devze.com 2023-02-19 01:45 出处:网络
I have been given some html that look like this (I have no control over the html): <p>Some text</p>

I have been given some html that look like this (I have no control over the html):

<p>Some text</p>
<strike>
  <p>This is some text</p>
</strike>
<p>More开发者_开发知识库 text</p>

The text shows as strikeout in both IE and Chrome, but not in Firefox. I have added display:inline-block to the <p> tag which fixes Firefox but then breaks IE and Chrome.

Is there a solution to this which will work in all three browsers and does not involve changing the html?


I believe your issue is due to nesting a block element (<p>) inside of an inline element (<strike>).

This CSS gets the line-through working in the nested <p>:

strike p {  /* only applies to <p> tags that are children of a <strike> tag */
    padding: 0;                     // remove default spacing from <p> tag
    text-decoration: line-through;  // fixes missing line-through
}

Note: Only tested in Firefox 3.6.x


Use CSS.

Tailored to your specific HTML example:

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

JSFiddle (verified to work in IE9, Chrome 10, FF4): http://jsfiddle.net/hcYVv/1/


That tag is not universally supported. Use the following CSS

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

and then accordingly change your html to

<p class="strikethrough">This is some text</p>
0

精彩评论

暂无评论...
验证码 换一张
取 消