我可以更改网站上的删除线的垂直位置吗?

jef*_*kee 21 html css

我正在使用删除标记

<s>$5,000,000</s>
Run Code Online (Sandbox Code Playgroud)

但线路太低了......从底部开始大约1/4,而不是从中间开始.我可以用任何方式修改它,以便在中间进行一些修改吗?

Rob*_*sto 9

你不能用strike标签或text-decoration:line-through样式来做.线路位置是内置的.你可以为此推出自己的风格,但这将是一个巨大的PITA.


Kei*_*ler 8

我已经编写了这段代码,让您可以完全控制穿透位置和样式:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Test</title>

<meta http-equiv="Content-type" content="text/html; charset=utf-8" />

<style type="text/css"> 

    .mark {
        border-bottom: 1px solid #000;
        top: -9px; /* Tweak this and the other top in equal, but opposite values */
        position: relative;
    }
    .offsetMark {
        position: relative;
        top: 9px; /* Tweak this and the other top in equal, but opposite values */
    }   

</style>     
</head>     
<body>        
<div>     
    <p class="strikethrough">This is an <span class="mark"><span class="offsetMark">example</span></span> of how I'd do it.</p>     
</div>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)