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

前端 未结 4 727
-上瘾入骨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]
    }
    
    0 讨论(0)
  • 2021-02-05 08:26

    Well, as long as the rest of the gradient (after your set number of pixels) can be a fixed color, just use three color stops as follows (this e.g. stops at 30px - notice the last entry is identical to the second):

    background: linear-gradient(to bottom, rgba(90,90,90,0.75) 0%,rgba(0,0,0,0.75) 30px,rgba(0,0,0,0.75) 100%);
    
    0 讨论(0)
  • 2021-02-05 08:31

    You can use the background-size property together.

    like this:

    
        
        div {
            height:100px;
            background:-moz-radial-gradient(center, ellipse farthest-corner, #323C49 0%, #718299 65%) no-repeat;
            background-size:auto 30px;
        }
        
    
    
    0 讨论(0)
  • 2021-02-05 08:38

    In CSS3:

    radial-gradient(ellipse at center center, 
      rgb(30, 87, 153) 0%, rgb(41, 137, 216) 100px, 
      rgba(255, 255, 255, 0) 101px, rgba(255, 255, 255, 0) 100%) 
    

    You can have multiple stops in the gradient. You can also specify length in pixels rather than percentages. You can also use rgba to make transparent colours.

    You start with your first colour at 0%, the center.
    Then you have the second colour at x pixels (I'm using x=100 pixels here).
    Then you go to transparent white at x+1 pixels.
    And stay transparent all the way until 100%.

    this should work in browsers that support CSS3.

    0 讨论(0)
提交回复
热议问题