how to make a css gradient stop after so many pixels?

前端 未结 4 777
-上瘾入骨i
-上瘾入骨i 2021-02-05 08:14
-moz-radial-gradient(center -200px , ellipse farthest-corner, #323C49 0%, #718299 65%) no-repeat scroll 0 0 transparent;

I have this code above and i j

4条回答
  •  情话喂你
    2021-02-05 08:21

    css3 gradients are background images so they will fill the entire height and width of the block element, just as if it were a solid color.

    In order to limit the height of the gradient, limit the height of the element. A "clean" way to do this might be to use a pseudo element. Something like...

    div {height: 500px; width: 500px; position: relative}
    
    div:before {
         content: " ";
         width: 100%;
         height: 30px;
         position: absolute;
         top: 0;
         left: 0;
         z-index: -1;
         display: block;
         background-image: [your-gradient-here]
    }
    

提交回复
热议问题