CSS fading top and bottom “borders”

前端 未结 2 1801
逝去的感伤
逝去的感伤 2020-12-13 08:08

Take a look at this : http://jsfiddle.net/wjhnX/

I achieved it with this CSS :

background-image: radial-gradient(#CCC, #FFF), radial-gradient(#CCC,          


        
相关标签:
2条回答
  • 2020-12-13 08:27

    you can make it with a seperator as well.

    LIVE DEMO

    .seperator
    {
        width: 400px;
        height: 2px;
        margin: 30px;
        background-image: radial-gradient(#CCC, #FFF), radial-gradient(#CCC, #FFF);
        background-position: 0, 100%, 0, 100%;
    }
    
    .one { 
        width: 400px;
        height: 140px;
        margin: auto;
    }
    
    0 讨论(0)
  • 2020-12-13 08:45

    Do you want something like this?

    Demo (Some breathing space for your content, I've used margin there, just make sure that it will apply to both, :before as well as :after, so if you want to separate, declare margin separately for each, p.s - I've made colors lil lighter)

    /* Using only background gradients */
    
    .one { 
        width: 400px;
        padding: 20px 25px;
        margin: 40px auto;
    }
    
    .one:before, .one:after {
        content: "";
        height: 1px;
        /* I've removed the vendor prefixes, if you are looking to support older browsers
           then refer to older version of this answer.
        */
        background: linear-gradient(to right,  rgba(0,0,0,0) 0%,rgba(147,147,147,1) 50%,rgba(0,0,0,0) 100%);
        display: block;
        margin-bottom: 10px;
        margin-top: 10px;
    }
    

    Explanation: I've used :before and :after pseudo having content: "", so it creates a block, you can say a virtual block inside the element... and which is further set to display: block, just make sure you use block there else margins and height will have no effect.. and last but not the least am using gradients with rgba to control the alpha/opacity of the gradient which will fade on both ends

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