任何 HTML 元素都可以设置为字段集/图例吗?
使用 display
属性,从样式角度来看,HTML 元素变得可以互换。然而,对于 fieldset
和 legend
来说,情况似乎并非如此。
是否可以将其他 HTML 元素设置为类似于 fieldset
和 legend
的样式?
Using the display
property, HTML elements become interchangeable from a styling perspective. This doesn't seem to be the case for fieldset
and legend
, however.
Is it possible to style other HTML elements to look like fieldset
and legend
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这工作得很好,但是如果背景是图像,ie6 会表现得有点奇怪,没有什么是条件注释不能解决的。在 IE6-8、FF3.6、Safari 5、Chrome 5 中测试
This works pretty good, but ie6 will act a bit strange if the background is an image, nothing a conditional comment couldn't fix. Tested in IE6-8, FF3.6, Safari 5, Chrome 5
前面的答案是不正确的,如果你想知道为什么尝试这个:
据我所知,没有办法在
fieldset
' 上产生legend
元素导致的边界破坏效果。的边界。我不认为单独使用 CSS 是可能的,它只是fieldset
标记呈现方式的一部分。澄清:我不知道有什么方法可以定位块或内联元素,使其横跨其包含块元素的可见边框,然后导致容器元素的边框在其框后面被破坏。这就是
对其包含的
The previous answer is incorrect, if you want to see why try this:
AFAIK there is no way to have that border-disruption effect that the
legend
element causes on thefieldset
's border. I don't believe that is possible with CSS alone, it's just something that is part of the way thefieldset
tag is rendered.Clarification: I don't know of any way to position a block or inline element such that it straddles the visible border of its containing block element, and then causes the container element's border to be broken behind its box. That's what a
<legend>
does to the border on its containing<fieldset>
element.当然,例如:带有边框的 DIV 元素和背景颜色设置为与 DIV 边框重叠的子标题元素看起来就像字段集和图例。
非常基本的例子:
Sure, for example: a DIV element with a border and a child heading element with the background color set positioned to overlap the DIV's border would look just like a fieldset and legend.
Very basic example:
所以我修复了代码,使其看起来有点像图例标签(它确实看起来像图例标签)。
So I fixed the code so that it looks somewhat (It really look like the legend tag) like the legend tag.