如何在HTML文本下添加虚线下划线

par*_*rap 84 html underline

你如何强调html文本,以便文本下面的行是点缀而不是标准下划线?最好,我想这样做而不使用单独的CSS文件.我是html的新手.

Alf*_*ing 130

没有CSS,这是不可能的.实际上,<u>标签只是text-decoration:underline使用浏览器的内置CSS 添加到文本中.

这是你可以做的:

<html>
<head>
<!-- Other head stuff here, like title or meta -->

<style type="text/css">
u {    
    border-bottom: 1px dotted #000;
    text-decoration: none;
}
</style>
</head>
<!-- Body, content here -->
</html>
Run Code Online (Sandbox Code Playgroud)

  • 你也可以尝试`dotted`而不是`dashed` (2认同)

epa*_*llo 15

如果没有CSS,你基本上都不习惯使用图片标签.基本上制作文本图像并添加下划线.这基本上意味着您的页面对屏幕阅读器毫无用处.

使用CSS,它很简单.

HTML:

<u class="dotted">I like cheese</u>
Run Code Online (Sandbox Code Playgroud)

CSS:

u.dotted{
  border-bottom: 1px dashed #999;
  text-decoration: none; 
}
Run Code Online (Sandbox Code Playgroud)

运行示例

示例页面

<!DOCTYPE HTML>
<html>
<head>
    <style>
        u.dotted{
          border-bottom: 1px dashed #999;
          text-decoration: none; 
        }
    </style>
</head>
<body>
    <u class="dotted">I like cheese</u>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)


Sha*_*med 15

使用以下CSS代码......

text-decoration:underline;
text-decoration-style: dotted;
Run Code Online (Sandbox Code Playgroud)

  • 有一个简短的语法:“text-decoration: underline #000 dotted;”,其中第一个属性是线条,第二个属性是颜色,第三个属性是样式。 (6认同)
  • 这应该是公认的答案。按照盒子模型,使用点状“边框”将放置在“填充”之外,从而远离文本。 (4认同)

Bar*_*Cap 9

也许我\xe2\x80\x99m有点晚了,但只需使用text-decoration: underline dotted,\nit\xe2\x80\x99s 一个可以在任何地方使用的CSS属性。

\n

内联 HTML

\n

\r\n
\r\n
<u style="text-decoration:underline dotted">I have a dotted underline</u>
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n

对于虚线下划线,请使用text-decoration: underline dashed.

\n

\r\n
\r\n
<u style="text-decoration:underline dashed">I have a dashed underline</u>
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n

正如 Darshana Gunawardana 所说,您可以使用text-underline-position: under, 在文本和行之间留出更多空间:

\n

\r\n
\r\n
<u style="text-decoration:underline dotted;text-underline-position:under">I have a dotted underline</u>
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n

在单独的 CSS 文件中

\n
u {\n  text-decoration: underline dotted;\n}\n
Run Code Online (Sandbox Code Playgroud)\n


Dar*_*ana 7

如果内容超过 1 行,添加底部边框将无济于事。在这种情况下你必须使用,

text-decoration: underline;
text-decoration-style: dotted;
Run Code Online (Sandbox Code Playgroud)

如果您希望文本和行之间有更多的喘息空间,只需使用,

text-underline-position: under;
Run Code Online (Sandbox Code Playgroud)


bis*_*hal 7

您可以利用text-decoration属性:

    text-decoration: underline;
    text-decoration-style: dotted;
    text-decoration-line: underline;
    text-decoration-thickness: 1px;
Run Code Online (Sandbox Code Playgroud)


小智 6

HTML5元素可以给出虚线下划线,因此下面的文本将具有虚线而不是常规下划线。当用户将光标悬停在元素上时,title属性会为用户创建工具提示:

注意:默认情况下,在Firefox和Opera中显示带虚线的边框/下划线,但是IE8,Safari和Chrome需要一行CSS:

<abbr title="Hyper Text Markup Language">HTML</abbr>
Run Code Online (Sandbox Code Playgroud)

  • 这只能用于缩写。否则屏幕阅读器可能会做错事。 (2认同)