css linear-gradient用法
时间: 2023-10-08 16:11:10 浏览: 89
CSS3,线性渐变(linear-gradient)的使用总结
CSS linear-gradient函数用于创建一个线性渐变的背景图像。这个函数可以接受多个颜色值作为参数,每个颜色值定义了渐变的一个色标点。渐变的方向由起点和终点决定。
示例用法:
background-image: linear-gradient(blue, blue) left top, linear-gradient(blue, blue) left top, linear-gradient(blue, blue) right top, linear-gradient(blue, blue) right top, linear-gradient(blue, blue) left bottom, linear-gradient(blue, blue) left bottom, linear-gradient(blue, blue) right bottom, linear-gradient(blue, blue) right bottom;
background-repeat: no-repeat;
background-size: 1px 24px, 24px 1px;
这个用法创建了一个四角边框效果,通过设置8个线性渐变来实现。每个线性渐变都使用相同的起点和终点,颜色值为blue,使得边框呈现蓝色。可以通过调整background-size来控制边框的粗细。
另外,线性渐变还可以用于创建棋盘效果。示例代码如下:
background-image: linear-gradient(90deg, rgba(0, 0, 0, 0.3) 10%, rgba(0, 0, 0, 0) 10%), linear-gradient(rgba(0, 0, 0, 0.3) 10%, rgba(0, 0, 0, 0) 10%);
background-size: 30px 30px;
background-color: white;
height: 200px;
这个用法创建了一个由黑色和透明色交替组成的棋盘效果。通过设置两个线性渐变,每个渐变的色标点包括一个透明点和一个黑色点,使得背景呈现交替的黑白方块。
总结来说,CSS linear-gradient函数可以通过设置不同的颜色值和参数调整来实现各种不同的渐变效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [【css】linear-gradient的几种用法](https://blog.csdn.net/yehuozhili/article/details/103401191)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [linear-gradient的用法详解](https://blog.csdn.net/u012436704/article/details/107189718)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [CSS3,线性渐变(linear-gradient)的使用总结](https://download.csdn.net/download/weixin_38702047/14906247)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文