是否可以模仿 CSS 脊线边框,但使用自定义颜色?

发布于 2024-08-12 18:26:23 字数 458 浏览 2 评论 0原文

我本质上希望有一个“山脊”样式的边框,但具有自定义颜色。使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夏至、离别 2024-08-19 18:26:23

不符合 CSS 3 规范(第 8.5.3 节):

为值绘制的边框颜色
“凹槽”、“脊”、“插入”和
“开始”取决于元素的
边框颜色属性,但 UA 可能
选择自己的算法
计算实际使用的颜色。

从技术上讲,我认为“选择自己的算法”可能涉及允许开发人员设置它们,但目前似乎没有用户代理这样做。当然,即使他们这样做了,您也只能找到针对该渲染引擎的解决方案。

Not per the spec for CSS 3 (Section 8.5.3):

The color of borders drawn for values
of 'groove', 'ridge', 'inset', and
'outset' depends on the element's
border color properties, but UAs may
choose their own algorithm to
calculate the actual colors used.

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.

夜未央樱花落 2024-08-19 18:26:23

您的示例似乎表明您想要创建一条脊线作为标题和其余部分之间的分隔符,而不是元素周围的脊状边框。为什么不使用 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.

不可一世的女人 2024-08-19 18:26:23

没有官方方法可以做到这一点,但您可以模仿效果。脊状边框实际上只是一个插入边框,它本身周围有一个起始边框(反过来,它只是一个实心边框,左/上和下/右的边框颜色略有不同)。

按照这些思路,您应该可以很好地近似您想要的东西,或者正是您正在寻找的东西。

 .inset{
      margin:0px;
      border: 1px inset #abc;
 }
 .outset{
      padding:0px;
      border:1px outset #cba;
 }

<div class='outset'>
     <div class='inset'>
          content goes here
     </div>
</div>

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.

 .inset{
      margin:0px;
      border: 1px inset #abc;
 }
 .outset{
      padding:0px;
      border:1px outset #cba;
 }

<div class='outset'>
     <div class='inset'>
          content goes here
     </div>
</div>
雪化雨蝶 2024-08-19 18:26:23
<style>
.a
{
        border: solid yellow 2px;
        border-top-color:red;
        border-left-color:red;

}
.b
{
        border: solid red 2px;
        border-top-color:yellow;
        border-left-color:yellow;
}
</style>
<div class='a'>
  <div class='b'>
        some text
  </div>
</div>
<style>
.a
{
        border: solid yellow 2px;
        border-top-color:red;
        border-left-color:red;

}
.b
{
        border: solid red 2px;
        border-top-color:yellow;
        border-left-color:yellow;
}
</style>
<div class='a'>
  <div class='b'>
        some text
  </div>
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文