--- title: border-top-color slug: Web/CSS/border-top-color tags: - CSS - CSS Borders - CSS属性 translation_of: Web/CSS/border-top-color --- <div>{{CSSRef}}</div> <p><strong><code>border-top-color</code></strong> 属性用以设置某元素顶部 {{cssxref("border")}}的颜色。通常,用{{cssxref("border-color")}} 或 {{cssxref("border-top")}} 设置该颜色更为便捷可取。</p> <div>{{EmbedInteractiveExample("pages/css/border-top-color.html")}}</div> <h2 id="语法">语法</h2> <pre class="brush: css no-line-numbers language-css">/* <color> values */ border-top-color: red; border-top-color: #ffbb00; border-top-color: rgb(255, 0, 0); border-top-color: hsla(100%, 50%, 25%, 0.75); border-top-color: currentColor; border-top-color: transparent; /* Global values */ border-top-color: inherit; border-top-color: initial; border-top-color: unset; </pre> <p><code>border-top-color</code> 属性的值为单值。</p> <h3 id="值">值</h3> <dl> <dt>{{cssxref("<color>")}}</dt> <dd>上边框的颜色。</dd> </dl> <h3 id="规范语法">规范语法</h3> {{csssyntax}} <h2 id="示例">示例</h2> <h3 id="一个简单的带边框容器">一个简单的带边框容器</h3> <h4 id="HTML">HTML</h4> <pre class="brush: html"><div class="mybox"> <p>This is a box with a border around it. Note which side of the box is <span class="redtext">red</span>.</p> </div></pre> <h4 id="CSS">CSS</h4> <pre class="brush: css">.mybox { border: solid 0.3em gold; border-top-color: red; width: auto; } .redtext { color: red; }</pre> <h4 id="结果">结果</h4> <p>{{EmbedLiveSample('A_simple_div_with_a_border')}}</p> <h2 id="Specifications">Specifications</h2> <table class="standard-table"> <thead> <tr> <th scope="col">Specification</th> <th scope="col">Status</th> <th scope="col">Comment</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('CSS3 Backgrounds', '#border-top-color', 'border-top-color')}}</td> <td>{{Spec2('CSS3 Backgrounds')}}</td> <td>No significant changes, though the <code>transparent</code> keyword, now included in {{cssxref("<color>")}} which has been extended, has been formally removed.</td> </tr> <tr> <td>{{SpecName('CSS2.1', 'box.html#border-color-properties', 'border-top-color')}}</td> <td>{{Spec2('CSS2.1')}}</td> <td>Initial definition</td> </tr> </tbody> </table> <p>{{cssinfo}}</p> <h2 id="浏览器兼容性">浏览器兼容性</h2> <p>{{Compat("css.properties.border-top-color")}}</p> <h2 id="See_also">See also</h2> <ul> <li>The border-related CSS shorthand properties: {{Cssxref("border")}}, {{Cssxref("border-top")}}, and {{Cssxref("border-color")}}.</li> <li>The color-related CSS properties for the other borders: {{Cssxref("border-right-color")}}, {{Cssxref("border-bottom-color")}}, and {{Cssxref("border-left-color")}}.</li> <li>The other border-related CSS properties applying to the same border: {{cssxref("border-top-style")}} and {{cssxref("border-top-width")}}.</li> </ul>