两种不同颜色的线性梯度效应

时间:2016-02-11 09:23:09

标签: css css3

我有两种颜色,红色和黄色。根据线性渐变格式,如果我们插入红色和黄色,它们之间会自动平滑过渡。如果我不想平滑过渡,我们如何在代码中表示它们?下面的代码是平滑过渡,但我不希望这两种颜色之间的平滑过渡。任何帮助请

<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
    height: 200px;
    background: linear-gradient(red, yellow);
}
</style>
</head>
<body>

<div id="grad1"></div>

</body>
</html>

4 个答案:

答案 0 :(得分:2)

使用此:

background: linear-gradient(to bottom, red 0%,red 50%,yellow 51%,yellow 100%);

Demo 网址现在返回404

答案 1 :(得分:0)

为什么你不只是将2个div放在另一个上面呢?

#grad1 {
    height: 100px;
    background: red;
}
#grad2 {
    height: 100px;
    background: yellow;
}

在此处查看:https://jsfiddle.net/eosx5cgc/

答案 2 :(得分:0)

我们可以在在线工具中生成CSS3渐变,例如colorzilla

&#13;
&#13;
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
    height: 200px;
    /* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#ff0000+0,ff0000+50,ffff00+51,ffff00+100 */
background: rgb(255,0,0); /* Old browsers */
background: -moz-linear-gradient(top,  rgba(255,0,0,1) 0%, rgba(255,0,0,1) 50%, rgba(255,255,0,1) 51%, rgba(255,255,0,1) 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(top,  rgba(255,0,0,1) 0%,rgba(255,0,0,1) 50%,rgba(255,255,0,1) 51%,rgba(255,255,0,1) 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom,  rgba(255,0,0,1) 0%,rgba(255,0,0,1) 50%,rgba(255,255,0,1) 51%,rgba(255,255,0,1) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff0000', endColorstr='#ffff00',GradientType=0 ); /* IE6-9 */


}
</style>
</head>
<body>

<div id="grad1"></div>

</body>
</html>
&#13;
&#13;
&#13;

答案 3 :(得分:0)

你可以

.tg {
  height: 75px;
  width: 400px;
  background-image: linear-gradient(135deg, red 60%, yellow 60.5%);
}

 <div class='tg'></div>

demo

enter image description here

相关问题