简体   繁体   English

更改CSS形状的边框颜色

[英]Changing border color of a CSS shape

I am trying to change the border-color of a CSS shape but unsuccessful. 我正在尝试更改CSS形状的边框颜色,但未成功。 Every time I play around the elements below, it changes the whole color of the shape. 每当我围绕以下元素玩耍时,它都会改变形状的整个颜色。

.pointer {
    width: 0;
    height: 0;
    border-top: 5px solid transparent;
    border-left: 10px solid red;
    border-bottom: 5px solid transparent;
    position:relative;
}

I want to be able to change the left, right, top, bottom border-color. 我希望能够更改左,右,上,下边框的颜色。 Can someone help out? 有人可以帮忙吗?

This is because the entire shape is the border. 这是因为整个形状都是边界。

The only way to create a border around an irregular shape that uses borders like you have is to either layer two of them or create it in a way that doesn't use borders 围绕使用不规则边界的不规则形状创建边界的唯一方法是要么将其中两个分层,要么不使用边界来创建边界

Here's a way to add border by layering another triangle 这是通过层叠另一个三角形来添加边框的方法

.pointer:before {
    content:'';
    position:absolute;
    left:-15px; /* position it to the left and top of the parent element */
    top:-10px;
    width: 0;
    height: 0;
    border-top: 10px solid transparent; /* Increase the size of it */
    border-left: 20px solid black;
    border-bottom: 10px solid transparent;
    z-index:-1; /* Put it behind the parent element */
}

Demo 演示版

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM