是否可以针对换行符 <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 page与 IE Net Renderer's IE8 engine ,并且成功了。
c69 做了一些进一步的调查,结果是你 can为br
设置标记相当重(虽然,不是跨浏览器),但这不会影响换行符本身,因为它似乎属于父容器。
关于html - 你可以用css定位<br/>吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/899252/