天空飘彩带的css3代码_6种精美的纯CSS3丝带效果_css3类似商城折扣提示层代码

一组非常精美的纯CSS3丝带设计效果。这组丝带效果分别使用:before和:after伪元素来制作各种丝带,适用于要使用丝带效果的各种不同场景。

这些丝带效果的HTML结构:使用一个

作为容器,在它里面放置一些 元素。元素及其伪元素用于制作各种丝带效果。

丝带效果1





2

丝带效果3

丝带效果4

丝带效果5

丝带效果6

div.ribbon是丝带的容器,丝带放置在它的上面。在例子中它被设置为内联块元素,宽度使用百分比,高度固定。采用相对定位方式,并为它设置了一张背景图片

.ribbon {

display: inline-block;

width: 48%;

height: 188px;

position: relative;

float: left;

margin-bottom: 30px;

background: url(../snow-road.jpg);

background-size: cover;

text-transform: uppercase;

color: white;

}

在屏幕的最大尺寸为500像素时(小屏幕设备),div.ribbon元素被设置为宽度占据整个视口的宽度。

@media (max-width: 500px) {

.ribbon {width: 100%}

.ribbon:nth-child(even) {margin-right: 0%;}

}

在第一种丝带效果中,外层的元素.ribbon1被设置为绝对定位方式,位于元素的右上角位置。

.ribbon1 {

position: absolute;

top: -6px;

right: 10px;

}

.ribbon1元素的:after伪元素用于制作丝带顶部的倒三角形。见图2

.ribbon1:after {

position: absolute;

content: "";

display: block;

width: 0;

height: 0;

border-left: 53px solid transparent;

border-right: 53px solid transparent;

border-top: 10px solid #F8463F;

}

.ribbon1元素中的元素用于制作丝带的主体。它是一个矩形,右上角被设置为圆角。见图3

.ribbon1 span {

position: relative;

display: inline-block;

text-align: center;

background: #F8463F;

font-size: 14px;

line-height: 1;

padding: 12px 8px 10px;

border-top-right-radius: 8px;

width: 90px;

}

.ribbon1 span元素的:before伪元素用于制作丝带左上角的背景效果。见图4

.ribbon1 span:before, .ribbon1 span:after {

position: absolute;

content: "";

display: block;

}

.ribbon1 span:before {

background: #F8463F;

height: 6px;

width: 6px;

left: -6px;

top: 0;

}

.ribbon1 span元素的:after伪元素用于制作丝带左上角的前景效果。见图5

.ribbon1 span:after {

background: #C02031;

height: 6px;

width: 8px;

border-radius: 8px 8px 0 0;

left: -8px;

top: 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是给出十常见的WS2812灯光效果代码示例: 1. 颜色渐变: ```C++ void colorWipe(uint32_t color, int wait) { for(int i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, color); strip.show(); delay(wait); } } ``` 2. 彩虹流动: ```C++ void rainbow(int wait) { for(int j=0; j<256; j++) { for(int i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, Wheel((i+j) & 255)); } strip.show(); delay(wait); } } uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if(WheelPos < 85) { return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); } else if(WheelPos < 170) { WheelPos -= 85; return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); } else { WheelPos -= 170; return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); } } ``` 3. 呼吸灯: ```C++ void breathe(int wait) { int max_bright = 255; int min_bright = 0; for(int i=min_bright; i<max_bright; i++) { for(int j=0; j<strip.numPixels(); j++) { strip.setPixelColor(j, strip.Color(i, i, i)); } strip.show(); delay(wait); } for(int i=max_bright; i>min_bright; i--) { for(int j=0; j<strip.numPixels(); j++) { strip.setPixelColor(j, strip.Color(i, i, i)); } strip.show(); delay(wait); } } ``` 4. 闪烁: ```C++ void blink(uint32_t color, int wait, int blink_times) { for(int i=0; i<blink_times; i++) { for(int j=0; j<strip.numPixels(); j++) { strip.setPixelColor(j, color); } strip.show(); delay(wait); for(int j=0; j<strip.numPixels(); j++) { strip.setPixelColor(j, strip.Color(0, 0, 0)); } strip.show(); delay(wait); } } ``` 5. 像素化: ```C++ void pixelate(uint32_t color, int wait) { int pixel_size = 5; for(int i=0; i<strip.numPixels(); i+=pixel_size) { for(int j=i; j<i+pixel_size; j++) { strip.setPixelColor(j, color); } strip.show(); delay(wait); for(int j=i; j<i+pixel_size; j++) { strip.setPixelColor(j, strip.Color(0, 0, 0)); } strip.show(); } } ``` 6. 火焰效果: ```C++ void flame(int wait) { for(int i=0; i<strip.numPixels(); i++) { int flicker = random(150); strip.setPixelColor(i, strip.Color(flicker+100, 0, 0)); } strip.show(); delay(wait); } ``` 7. 音乐节奏: ```C++ void music(int wait) { int bass = analogRead(A0); int treble = analogRead(A1); int mid = analogRead(A2); int total = (bass+treble+mid)/3; for(int i=0; i<strip.numPixels(); i++) { int brightness = map(total, 0, 1023, 0, 255); strip.setPixelColor(i, strip.Color(brightness, 0, 0)); } strip.show(); delay(wait); } ``` 8. 星空效果: ```C++ void stars(int wait) { for(int i=0; i<strip.numPixels(); i++) { int flicker = random(150); strip.setPixelColor(i, strip.Color(flicker, flicker, flicker)); } strip.show(); delay(wait); } ``` 9. 渐变循环: ```C++ void gradientCycle(int wait) { int r, g, b; for(int k=0; k<256; k++) { for(int j=0; j<strip.numPixels(); j++) { r = sin(0.3*j+k/10.0) * 127 + 128; g = sin(0.3*j+k/10.0) * 127 + 128; b = sin(0.3*j+k/10.0) * 127 + 128; strip.setPixelColor(j, strip.Color(r, g, b)); } strip.show(); delay(wait); } } ``` 10. 彩带效果: ```C++ void ribbon(int wait) { for(int i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, strip.Color(255, 0, 0)); } strip.show(); delay(wait); for(int i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, strip.Color(0, 255, 0)); } strip.show(); delay(wait); for(int i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, strip.Color(0, 0, 255)); } strip.show(); delay(wait); } ``` 注意:这些代码只是示例,实际使用时需要根据具体情况进行修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值