首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用CSS在BR标记后添加em空格( )

问如何使用CSS在BR标记后添加em空格( )
EN

Stack Overflow用户
提问于 2019-09-25 07:57:15
回答 2查看 818关注 0票数 0

我想在BR标签后面加一个空格,以达到文本缩进的效果。但以下风格在我的Chrome上不起作用。

或者,有没有其他方法可以在BR标签之后实现文本缩进效果?

代码语言:javascript
复制
<style>
br::after { 
  content: "&emsp;";
}
</style>

<p>Note:<br>For this selector to work in IE8, a DOCTYPE must be declared, and you must use the old, single-colon CSS2 syntax (:after instead of ::after).</p>
EN

回答 2

Stack Overflow用户

发布于 2019-09-25 09:55:45

你真的不应该使用换行(br)标签来分隔段落,在现代网页设计中是不应该的。有关示例,请参阅HTML 5.2 spec。

此外,还有一个CSS属性text-indent,它也可以实现您想要的文本缩进。

基本上,按照预期使用<p> (例如,对段落进行换行),然后将text-indent应用于p标签。

​

代码语言:javascript
复制
p {
  text-indent: 1em;
}
p.unindented {
  text-indent: inherit;
}
代码语言:javascript
复制
<p class="unindented">Note:</p>
<p>For this selector to work in IE8, a DOCTYPE must be declared, and you must use the old, single-colon CSS2 syntax (:after instead of ::after).</p>
<p>Here is another paragraph to show how this applies when you have more than one &lt;p&gt; of content. The text-indent property is supported by all major browsers. (That is, IE 3 and later. Not that IE is a major browser anymore....)</p>
<p>See here for more info: https://developer.mozilla.org/en-US/docs/Web/CSS/text-indent</p>

​

text-indent是一个非常古老的属性,它广泛支持所有主流浏览器,也支持很多更老的浏览器。它最早是在IE3中引入的,目的是让人们了解它有多老。有关详细信息,请参阅MDN。

票数 1
EN

Stack Overflow用户

发布于 2019-09-25 09:25:14

我设法在BR标签后面添加了一个em空格!

代码语言:javascript
复制
<style>
br {
  content: '';
  white-space: pre;
}

br::after { 
  content: "\A\2003";
}
</style>

另一个问题是,我也想保持1em的边际底部。下面的风格本身就能很好地工作。

代码语言:javascript
复制
<style>
br {
  content: '';
  display: block; 
  margin-bottom: 1em; 
}
</style>

但是,如果我将这两种风格混合到下面的代码中,它就不能工作了!

代码语言:javascript
复制
<style>
br {
  content: '';
  white-space: pre;
  display: block; 
  margin-bottom: 1em; 
}

br::after { 
  content: "\A\2003";
}
</style>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58089465

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档