<font color="#c41230">设置1px的渐变背景,50%有颜色,50%透明。很多UI都是采用这种方法,比如:weui、mint-ui...</font>
单边
.background-gradient-1px {<br>background-image: linear-gradient(180deg, #000, #000 50%, transparent 50%);<br>background-size: 100% 1px;<br>background-repeat: no-repeat;<br>background-position: bottom left;<br>background-origin: border-box;<br>}
相关 CSS 属性与函数
linear-gradient()
<font color="#c41230">CSS linear-gradient() 函数用于创建一个表示两种或多种颜色线性渐变的图片。<br>其结果属于<gradient>数据类型,是一种特别的<image>数据类型。</font><br>
语法
linear-gradient(<br> [ <angle> | to <side-or-corner> ,]? <color-stop-list> )<br> \-------------------------/ \----------------------------/<br> Definition of the gradient line List of color stops <br><br>where <side-or-corner> = [ left | right ] || [ top | bottom ]<br> and <color-stop-list> = [ <linear-color-stop> [, <color-hint>? ]? ]#, <linear-color-stop><br> and <linear-color-stop> = <color> [ <color-stop-length> ]?<br> and <color-stop-length> = [ <percentage> | <length> ]{1,2}<br> and <color-hint> = [ <percentage> | <length> ]
background-origin
<font color="#c41230">The background-origin CSS property sets the background's origin: <br>from the border start, inside the border, or inside the padding.</font><br>
四边
.background-gradient-1px {<br>// <font color="#c41230">多个背景</font><br>background:<br> linear-gradient(<b>90deg</b>,red, red 50%, transparent 50%) left / 1px 100% no-repeat<font color="#c41230"><b>,</b></font><br> linear-gradient(<b>90deg</b>,blue, blue 50%, transparent 50%) right / 1px 100% no-repeat<b><font color="#c41230">,</font></b><br> linear-gradient(purple, purple 50%, transparent 50%) top / 100% 1px no-repeat<b><font color="#c41230">,</font></b><br> linear-gradient(green, green 50%, transparent 50%) bottom / 100% 1px no-repeat<br>}<br>