html - 你可以用css定位<br/>吗?

标签 html css line-breaks

是否可以针对换行符 <br/>用 CSS 标记?

我希望每次有换行符时都有一条 1px 的虚线。我正在使用自己的 CSS 自定义网站,无法更改设置的 HTML,否则我会使用其他方式。

我不认为这是可能的,但也许有人知道。

最佳答案

从技术上讲,是的,您可以定位 <br>直接使用 CSS 元素或通过将类应用到它并定位该类。话虽这么说,一个<br>生成一个换行符,它只是一个换行符。由于此元素没有内容,因此只有少数样式可以应用在其上,例如 clear position .您可以设置<br>的边框,但您不会看到它,因为它没有视觉维度。

如果您想在视觉上将两个句子分开,那么您可能想要使用 horizontal ruler这是为了这个目标。由于您无法更改标记,因此仅使用 CSS 恐怕无法实现此目的。

看来,已经在其他论坛讨论过了。摘自 Re: Setting the height of a BR element using CSS :

[T]his leads to a somewhat odd status for BR in that on the one hand it is not being treated as a normal element, but instead as an instance of \A in generated content, but on the other hand it is being treated as a normal element in that (a limited subset of) CSS properties are being allowed on it.

我还在 CSS 1 specification 中找到了说明。 (没有更高级别的规范提到它):

The current CSS1 properties and values cannot describe the behavior of the ‘BR’ element. In HTML, the ‘BR’ element specifies a line break between words. In effect, the element is replaced by a line break. Future versions of CSS may handle added and replaced content, but CSS1-based formatters must treat ‘BR’ specially.

Grant Wagner's tests显示无法设置样式BR就像你可以对其他元素一样。网上还有一个网站可以test the results in your browser .

pelms 做了一些进一步的调查,pointed out IE8(在 Win7 上)和 Chrome 2/Safari 4b 允许您设置 BR有些。事实上,我检查了IE demo pageIE Net Renderer's IE8 engine ,并且成功了。

c69 做了一些进一步的调查,结果是你 canbr 设置标记相当重(虽然,不是跨浏览器),但这不会影响换行符本身,因为它似乎属于父容器。

关于html - 你可以用css定位<br/>吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/899252/

相关文章:

html - 行内 block 元素和垂直对齐推理

css - 如何将无序列表中的 li 元素内的文本居中

html - 单击元素后面的按钮

asp.net - 如何防止asp.net中Title标签换行?

html - 如何在 DIV 中的长单词中强制换行?

javascript - 当鼠标在框上时停止动画并在鼠标移出时将其动画回来,不起作用

html - CSS3 动画过渡 : opacity not working

html - 我正在尝试在页脚内放置一个容器。我可以将它左右放置,但我不确定为什么它不会进入中间

html - 是否可以在警报中使用 Bootstrap (v3) 网格系统?

css - 以多行显示标签文本