每行写一个句子并需要空间,但一个语义段落应该使用 <br/> 或 <p>

问题描述 投票:0回答:1

我正在销售页面上以这种风格编写长文案(为简洁起见,已缩短):

我们明白了……

找到一个理解 X 的 X 是很困难的。

看起来他们都是X。

那么,你应该如何决定?

这是一个有内涵的问题,但我们可以告诉你的是:

我应该使用双
标签将其保留在单个语义段落中,还是应该为每一行使用

标签,即使它们是同一想法的一部分?

最初我是这样写的:

<p>
  We get it..
  <br/><br/>
  Finding an X that understand X is difficult.
  <br/><br/>
  It seems like they all X.
  <br/><br/>
  So, how are you supposed to decide?
  <br/><br/>
  That's a loaded question, but what we can tell you is this:
</p>

我的思考过程是,这一切都应该是一个想法的一部分,并且我试图在语义上和可访问性上保持清醒。

问题是对我来说,使用两个

<br/>
标签来创建空间是不可取的,并且根据我在这里看到的其他线程,语义上可能不正确。这不是诗歌,也不是邮寄地址,不是。但这只是一个想法。

然后我尝试使用单个

<br/>
标签,然后去设置它的样式却发现我不能。

所以我决定将每一行包装在自己的

<p>
标签中(更容易使用 CSS 进行空间样式设置)。

<p>We get it..</p>
<p>Finding an X that understand X is difficult.</p>
<p>It seems like they all X.</p>
<p>So, how are you supposed to decide?</p>
<p>That's a loaded question, but what we can tell you is this:</p>

但我仍然不确定这是否是语义和可访问性的问题。

就我的目的而言,哪种方法是正确的?

html css accessibility semantic-markup
1个回答
0
投票

不要将标签用于样式,而将它们用于结构。如果数据的语义是这都是一个段落,则将其全部设为一个段落:

<p>We get it…
Finding an X that understands X is difficult.
It seems like they all X.
So, how are you supposed to decide?
That's a loaded question, but what we can tell you is this:</p>

然后,如果该段落的样式需要在行之间留有空格,请为此添加 CSS 规则:

p {
  white-space: pre;
  line-height: 2rem;
}
<p>We get it…
Finding an X that understands X is difficult.
It seems like they all X.
So, how are you supposed to decide?
That's a loaded question, but what we can tell you is this:</p>

© www.soinside.com 2019 - 2024. All rights reserved.