是否可以模仿 CSS 脊线边框,但使用自定义颜色?
我本质上希望有一个“山脊”样式的边框,但具有自定义颜色。使用 border-style: ridge
似乎您无法放入不同的颜色,浏览器仅使用比指定颜色稍浅的一种颜色和一种稍深的颜色。
我当前的解决方案是这样的,但由于额外的
,它并不理想。<div id="header">
<!-- block with border-bottom set to `1px solid #2e3436`-->
</div>
<div style="height: 1px; background-color: #fbe995;"></div>
下面的下一项不能将其顶部边框设置为该颜色(它有自己的样式并且是单独的) ),所以这个想法就消失了。还有什么我可以尝试的吗?
I essentially wish to have a "ridge" style border but with custom colors. With border-style: ridge
it seems you can't put different colours in, the browser just uses one slightly lighter and one slightly darker than the colour specified.
My current solution is this, but it's not ideal due to the extra <div>
<div id="header">
<!-- block with border-bottom set to `1px solid #2e3436`-->
</div>
<div style="height: 1px; background-color: #fbe995;"></div>
The next item below this can't have its top border set to that colour (it has its own styles and is separate), so that idea is out. Is there anything else I can try?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不符合 CSS 3 规范(第 8.5.3 节):
从技术上讲,我认为“选择自己的算法”可能涉及允许开发人员设置它们,但目前似乎没有用户代理这样做。当然,即使他们这样做了,您也只能找到针对该渲染引擎的解决方案。
Not per the spec for CSS 3 (Section 8.5.3):
Technically I suppose that "choose their own algorithm" could involve allowing the developer to set them, but no user-agent seems to do that at this point. Of course, even if they did, you'd have a solution for only that rendering engine.
您的示例似乎表明您想要创建一条脊线作为标题和其余部分之间的分隔符,而不是元素周围的脊状边框。为什么不使用
hr
来实现这一点,因为这正是它的用途呢?然后您可以给它一个边框并在不同的侧面设置您自己的颜色。
Your example seems to suggest you want to create a ridged line as a separator between your header and the rest, rather than a ridged border around an element. Why don't you use a
hr
for that, since that's pretty much exactly what it's for?You can then give it a border and set your own colors on the different sides.
没有官方方法可以做到这一点,但您可以模仿效果。脊状边框实际上只是一个插入边框,它本身周围有一个起始边框(反过来,它只是一个实心边框,左/上和下/右的边框颜色略有不同)。
按照这些思路,您应该可以很好地近似您想要的东西,或者正是您正在寻找的东西。
There's no official way to do this, but you could probably mimic the effect. A ridged border is really just an inset border which itself has an outset border around it (which in turn is just a solid border with slightly different border colors for left/top and bottom/right).
Something along these lines should get you a pretty good approximation of what you want, or exactly what you were looking for.