换行后我可以缩进吗?

时间:2022-01-05 07:23:49

I have got only one paragraph with few line breaks. Can i indent text after each?

我只有一个段落,几个换行符。我可以在每次之后缩进文字吗?

<p>
   Some text</br>
   More text</br>
   More text</br>
</p>

I have no ability to put <p></p> instead of </br> and use p{text-indent=1em;}

我无法将

代替 并使用p {text-indent = 1em;}

2 个解决方案

#1


2  

The following works in Chrome, Opera, and Safari. Still trying to figure out a solution for IE and Firefox.

以下适用于Chrome,Opera和Safari。仍试图找出IE和Firefox的解决方案。

This method assumes you know the maximum number of brs in your source. I'm using </br> like you did, based on your comment that it's that way in the database.

此方法假定您知道源中的最大brs数。我正在使用 ,就像你在数据库中那样评论一样。

br {
  content: '';
  white-space: pre;
}

br:nth-child(1):after {content: '\A   ';}
br:nth-child(2):after {content: '\A      ';}
br:nth-child(3):after {content: '\A         ';}
br:nth-child(4):after {content: '\A            ';}
br:nth-child(5):after {content: '\A               ';}
br:nth-child(6):after {content: '\A                  ';}
br:nth-child(7):after {content: '\A                     ';}
br:nth-child(8):after {content: '\A                        ';}
br:nth-child(9):after {content: '\A                           ';}
<p>
  Some text</br>
  More text</br>
  More text</br>
  More text</br>
  More text</br>
  More text</br>
  More text</br>
  More text</br>
  More text</br>
  More text</br>
</p>

#2


0  

No, you cannot, because there is no element to apply such styling on. The <br> element has no content, and it is unspecified whether you can use :before and :after pseudo-elements on them—in practice you cannot.

不,你不能,因为没有元素可以应用这样的样式。
元素没有内容,并且未指定是否可以使用:before和:after伪元素 - 实际上你不能。

You should process the data or change the current processing so that whatever is meant to be a paragraph is marked up as a p element (and your current p markup should be replaced by div, or maybe section). That way the styling problem becomes solvable (and rather easy).

您应该处理数据或更改当前处理,以便将段落中的任何内容标记为p元素(并且您当前的p标记应替换为div,或者可能替换为section)。这样,样式问题变得可以解决(而且相当简单)。

#1


2  

The following works in Chrome, Opera, and Safari. Still trying to figure out a solution for IE and Firefox.

以下适用于Chrome,Opera和Safari。仍试图找出IE和Firefox的解决方案。

This method assumes you know the maximum number of brs in your source. I'm using </br> like you did, based on your comment that it's that way in the database.

此方法假定您知道源中的最大brs数。我正在使用 ,就像你在数据库中那样评论一样。

br {
  content: '';
  white-space: pre;
}

br:nth-child(1):after {content: '\A   ';}
br:nth-child(2):after {content: '\A      ';}
br:nth-child(3):after {content: '\A         ';}
br:nth-child(4):after {content: '\A            ';}
br:nth-child(5):after {content: '\A               ';}
br:nth-child(6):after {content: '\A                  ';}
br:nth-child(7):after {content: '\A                     ';}
br:nth-child(8):after {content: '\A                        ';}
br:nth-child(9):after {content: '\A                           ';}
<p>
  Some text</br>
  More text</br>
  More text</br>
  More text</br>
  More text</br>
  More text</br>
  More text</br>
  More text</br>
  More text</br>
  More text</br>
</p>

#2


0  

No, you cannot, because there is no element to apply such styling on. The <br> element has no content, and it is unspecified whether you can use :before and :after pseudo-elements on them—in practice you cannot.

不,你不能,因为没有元素可以应用这样的样式。
元素没有内容,并且未指定是否可以使用:before和:after伪元素 - 实际上你不能。

You should process the data or change the current processing so that whatever is meant to be a paragraph is marked up as a p element (and your current p markup should be replaced by div, or maybe section). That way the styling problem becomes solvable (and rather easy).

您应该处理数据或更改当前处理,以便将段落中的任何内容标记为p元素(并且您当前的p标记应替换为div,或者可能替换为section)。这样,样式问题变得可以解决(而且相当简单)。