CSS fade out horizontal rule / line styled div effect without images

后端 未结 5 889
故里飘歌
故里飘歌 2020-12-14 04:07

I\'m a big fan of minimal use of images and was wondering if anyone had a tactic (or if it\'s possible) to create this kind of thing with pure static CSS?

http://ww

相关标签:
5条回答
  • 2020-12-14 04:11

    In order to reproduce that horizontal rule, you can use a CSS3 linear-gradient. Just create a div with about a 3px height and apply the following CSS (change the colors as needed):

    background: #ffffff; /* Old browsers */
    background: -moz-linear-gradient(left,  #ffffff 0%, #2989d8 25%, #207cca 75%, #ffffff 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, right top, color-stop(0%,#ffffff), color-stop(25%,#2989d8), color-stop(75%,#207cca), color-stop(100%,#ffffff)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(left,  #ffffff 0%,#2989d8 25%,#207cca 75%,#ffffff 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(left,  #ffffff 0%,#2989d8 25%,#207cca 75%,#ffffff 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(left,  #ffffff 0%,#2989d8 25%,#207cca 75%,#ffffff 100%); /* IE10+ */
    background: linear-gradient(left,  #ffffff 0%,#2989d8 25%,#207cca 75%,#ffffff 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#ffffff',GradientType=1 ); /* IE6-9 */
    

    Keep in mind that filter does not support color stops, so you may want an image fall back for < IE10.

    Build your own CSS3 gradient here: http://www.colorzilla.com/gradient-editor/

    0 讨论(0)
  • 2020-12-14 04:12

    This code create a normal hr but the difference will is it will have both end with fade effect(gradient black to blue)

    hr{
    border-top-color: black;
    margin-bottom: 25px;
    width: 80%;
    }
    hr::before{
    display: block;
    margin-left: -10%;
    margin-top: -1px;
    content:"";
    background: linear-gradient(to left, black, blue);
    width: 10%;
    height: 1px;
    }
    hr::after{
    display: block;
    margin-left: 100%;
    margin-top: -1px;
    content:"";
    background: linear-gradient(to right, black, blue);
    width: 10%;
    height: 1px;
    }
    
    0 讨论(0)
  • 2020-12-14 04:15

    Ok so I've answered my own question but I've read the Stackoverflow forums and it seems to be acceptable (if not actually encouraged!)

    So...

    HTML:

    <html>
    <head>
    <TITLE>TEST</TITLE>
    <link rel="stylesheet" type="text/css" href="test.css" />
    </head>
    <body>
    
    <div id="wrap">
    <div id="gradient">
    </div>
    </div>
    
    </body>
    </html>
    

    CSS:

    #wrap
    {
    overflow:hidden;
    height:10px;
    width:600px;
    height:20px;
    margin:auto;
    margin-top:200px;
    }
    
    
    #gradient
    {
    height:20px;
    width:580px;
    margin:auto;
    margin-top:-11px;
    background: -moz-radial-gradient(center, ellipse cover,  rgba(10,10,10,1) 0%, rgba(8,8,8,1) 19%, rgba(3,3,3,0) 80%, rgba(1,1,1,0) 100%); /* FF3.6+ */
    background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%,rgba(10,10,10,1)), color-stop(19%,rgba(8,8,8,1)), color-stop(80%,rgba(3,3,3,0)), color-stop(100%,rgba(1,1,1,0))); /* Chrome,Safari4+ */
    background: -webkit-radial-gradient(center, ellipse cover,  rgba(10,10,10,1) 0%,rgba(8,8,8,1) 19%,rgba(3,3,3,0) 80%,rgba(1,1,1,0) 100%); /* Chrome10+,Safari5.1+ */
    background: -o-radial-gradient(center, ellipse cover,  rgba(10,10,10,1) 0%,rgba(8,8,8,1) 19%,rgba(3,3,3,0) 80%,rgba(1,1,1,0) 100%); /* Opera 12+ */
    background: -ms-radial-gradient(center, ellipse cover,  rgba(10,10,10,1) 0%,rgba(8,8,8,1) 19%,rgba(3,3,3,0) 80%,rgba(1,1,1,0) 100%); /* IE10+ */
    background: radial-gradient(center, ellipse cover,  rgba(10,10,10,1) 0%,rgba(8,8,8,1) 19%,rgba(3,3,3,0) 80%,rgba(1,1,1,0) 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#0a0a0a', endColorstr='#00010101',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */
    }
    
    0 讨论(0)
  • 2020-12-14 04:33

    hr {
      height: 1px;
      margin: 50px 0;
      background: -webkit-gradient(linear, 0 0, 100% 0, from(rgba(0, 0, 0, 0)), color-stop(0.5, #333333), to(rgba(0, 0, 0, 0)));
      background: -webkit-linear-gradient(left, rgba(0, 0, 0, 0), #333333, rgba(0, 0, 0, 0));
      background: -moz-linear-gradient(left, rgba(0, 0, 0, 0), #333333, rgba(0, 0, 0, 0));
      background: -o-linear-gradient(left, rgba(0, 0, 0, 0), #333333, rgba(0, 0, 0, 0));
      background: linear-gradient(left, rgba(0, 0, 0, 0), #333333, rgba(0, 0, 0, 0));
      border: 0;
    }
    hr:after {
      display: block;
      content: '';
      height: 30px;
      background-image: -webkit-gradient(radial, 50% 0%, 0, 50% 0%, 116, color-stop(0%, #cccccc), color-stop(100%, rgba(255, 255, 255, 0)));
      background-image: -webkit-radial-gradient(center top, farthest-side, #cccccc 0%, rgba(255, 255, 255, 0) 100%);
      background-image: -moz-radial-gradient(center top, farthest-side, #cccccc 0%, rgba(255, 255, 255, 0) 100%);
      background-image: -o-radial-gradient(center top, farthest-side, #cccccc 0%, rgba(255, 255, 255, 0) 100%);
      background-image: radial-gradient(farthest-side at center top, #cccccc 0%, rgba(255, 255, 255, 0) 100%);
    }
    <hr>

    0 讨论(0)
  • 2020-12-14 04:36

    You can use CSS3's stops and the :after pseudo-element to achieve such an effect. The trick is to add a border to the <hr> element by using the :after pseudo-element and position it in the center of the initial gradient with a soft color that ends with the gradient.

    Here is a quick demo, and another demo using some color.

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