2015-01-31 53 views
0

您好,我如何添加到從左到右的僞元素漸變效果。 我試圖:如何添加僞元素漸變效果

.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 --> 

上面的代碼繪製清晰的線,但我想創造的東西是這樣的:

enter image description here

我的整個代碼爲:

.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; 
} 
+1

您可能想澄清「僞元素梯度效應」的含義。 – 2015-01-31 19:02:12

+0

它繪製了一條線,但我希望它像這樣漸變.http://3.bp.blogspot.com/--mnE6qvKvuQ/VM0nYdKASnI/AAAAAAAAAGI/5QIfWHza3PM/s1600/Screenshot_2.png – Dragut 2015-01-31 19:07:05

+0

它正在繪製尖銳因爲有一個邊框被應用到元素 – 2015-01-31 19:10:42

回答

0

回覆Bergmann的問題到原來的答案:

你可以模擬漸變的邊界很少額外的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/

在此示例中.element填充用於模擬邊界。

2
.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%); 
}