CSS中如何给图形填充颜色在CSS中,我们可以使用各种形状来创建图形。但是,如果我们想要为这些图形添加颜色,该怎么做呢?下面,我们将介绍几种方法。1. 使用backgroundcolor属性我们可以使...
CSS中如何给图形填充颜色
在CSS中,我们可以使用各种形状来创建图形。但是,如果我们想要为这些图形添加颜色,该怎么做呢?下面,我们将介绍几种方法。
1. 使用background-color属性
我们可以使用background-color属性为任何元素(包括形状)添加背景颜色。
例如,为了将圆形的背景颜色设置为红色,可以使用以下CSS代码:
.circle {
width: 100px;
height: 100px;
border-radius: 50%;
background-color: red;
}
.circle {
width: 100px;
height: 100px;
border-radius: 50%;
background: linear-gradient(to bottom right, red, yellow);
}
.circle {
width: 100px;
height: 100px;
border-radius: 50%;
background-image: url('grid.png');
}