【发布时间】:2021-09-24 17:15:30
【问题描述】:
有没有办法格式化 HTML 属性值,使它们跨越多行? 本质上,我问的是有没有办法在常规类型的 HTML 属性值中转义返回。
例如,在下面这个工作代码中,我们在一行中有href 属性值。
<head>
<!-- Bootstrap CSS -->
<link
rel="stylesheet"
href= "https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
> <!-- href value above spans 1 line and wraps normally with text editors width -->
</head>
<body>
<h1>Bootstrap has successfully applied because this font is sans-serif</h1>
</body>
我怎样才能让这种格式的unworking代码具有跨越multiple行的属性值才能工作?:
<head>
<!-- Bootstrap CSS -->
<link
rel="stylesheet"
href= "https://cdn.jsdelivr.net/npm/
bootstrap@5.0.2/dist/css/
bootstrap.min.css"
> <!-- href value above spans 3 lines -->
</head>
<body>
<h1>
Bootstrap hasn't applied due to the amount of
<mark>enter</mark> characters used in the <mark>href</mark> attribute
</h1>
</body>
似乎一旦你将返回值添加到一个值中,整个值就会失败。我尝试了常规的 javaScript 转义字符,但没有成功。
如何在 HTML 属性中成功添加返回(新行)价值观?
【问题讨论】:
-
我认为从规范的角度来看,您可以在 html 属性中添加新行,但它们无法被浏览器中的
linkscript或其他标签识别 -
@ashishmaurya 所以这可以在不同的标签上工作吗?可能是
h1标签上的类名? -
是的,只是不要破坏你的类名(否则 CSS 将不起作用)
-
我不相信 HTML 属性有一个 line continue 构造。
-
即使它删除了换行符,我希望它用一个空格替换它,比如
class='make-the- text-purple'(实际上,属性中还有空格,而不仅仅是换行符) .浏览器被告知有空格需要考虑,所以它会考虑,即使它对待其中的一些是特殊的。
标签: html syntax attributes escaping html-escape-characters