【发布时间】:2015-12-02 18:13:05
【问题描述】:
我正在尝试设置 blockquote 和子 cite 元素的样式以复制 fieldset 和 legend 元素的外观,其中字段集周围有边框,图例标签插入边界的顶部——如果你看过一个字段集,你就会明白我的意思。
我有一个解决方案,我给cite 一个背景颜色,但这只有在放置在类似颜色的背景上时才有效。 我需要一个适用于 IE8+ 中所有背景、bg 图片等的解决方案
假设以下标记(不能由此更改。不允许其他元素):
<blockquote class="quote">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptas rem, animi
facere illum deserunt nam ipsa, et sapiente quisquam sed repudiandae aliquam
delectus. Reiciendis repellat illo, et natus earum odit!
<cite class="attribution">Mr. Jefferson</cite>
</blockquote>
我目前拥有的 CSS:
.quote {
border: 4px solid black;
padding: 1rem;
position: relative;
}
.attribution {
position: absolute;
top: 0;
left: 1rem;
margin-top: -0.65rem;
padding: 0 1rem;
background: white; /* this works, but breaks if the background isn't white. I need a solution that works for all possible page bg colors */
}
【问题讨论】:
-
“从父级继承背景颜色,除非父级有
transparent,在这种情况下从其父级递归继承”没有CSS,所以恐怕你必须使用Javascript来做那个。 -
@MrLister 这不是我要问的。我只想让它透明。背景颜色技术只是一种技巧。它应该复制字段集/图例的行为。使用背景颜色是我能得到的最接近的颜色,我特别不想使用背景颜色。
-
但问题是,当你使用透明时,父级的边框在文本后面是可见的。你需要一个背景。