Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add a pseudo-element gradient effect

Tags:

css

Hello how could i add to a pseudo-element gradient effect from left to right. i'm trying:

.divider p:after {
    content: "";
    position: absolute;
    top: 50%;
    left: 0;
    right: 25%;
    z-index: -1;
    border-top: 1px solid #666666;
}

HTML

<div class="divider">
 <p><span>Featured</span></p>

 </div><!-- end of divider -->

above code draws a sharp line,but i would like create something like this:

enter image description here

my whole code was:

.divider {
color: #666666;
}
.divider p span {
margin:0;padding: 0 10px;
background: #FFFFFF;
display: inline-block;
}
.divider p {
padding-left: 20px;
position: relative;
z-index: 2;   
}
.divider p:after {
content: "";
position: absolute;
top: 50%;
left: 0;
right: 25%;
z-index: -1;
border-top: 1px solid #666666;
}
like image 581
Dragut Avatar asked Jan 31 '15 19:01

Dragut


2 Answers

.box:before,
.box:after {
  content: "";
  position: absolute;
  display: block;
  left: -10px;
  width: 1px;
  height: 50%;
}

.box:before {
  top: 0;
  background: linear-gradient(to top, #333 0%, transparent 100%);
}

.box:after {
  bottom: 0;
  background: linear-gradient(to bottom, #333 0%, transparent 100%);
}
like image 114
Bacs Avatar answered Oct 14 '22 00:10

Bacs


In response to Bergmann's question to the original answer:

You could simulate solid gradient borders with little extra css.

HTML:

<div class="element">
    <div class="content">
        Content
    </div>
</div>

CSS:

.element {
    position: relative;
    padding: 5px;
}
.element:before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 100%;
    background-image: linear-gradient(90deg, #000 0%, #fff 100%);
}
.content {
    position: relative;
    background-color:white;
}

http://jsfiddle.net/nu9zmxvw/

In this sample the .element padding is used to simulate border.

like image 33
chris Avatar answered Oct 13 '22 22:10

chris