【发布时间】:2013-04-28 15:58:12
【问题描述】:
我的标题是横向延伸的(灵感来自 Chris Coyiers example)。我试图通过将它们与渐变背景重叠来淡化边界。但是,我无法让它工作,但我觉得它应该以某种方式成为可能。为了说明我在寻找什么效果:
这就是我现在拥有的:
这就是我想要实现的目标:
我现在的代码:
HTML
<article>
<p>Lorem ipsum etc.</p>
<p class="fancy">
<a href="#">read more</a>
</p>
</article>
CSS
body {
background: red; /* Just to show the effect of the transparency, the final background will be white */
font-size: 150%;
}
/* This is for the horizontal borders extending sideways from the heading */
.fancy a {
max-width: 100%;
margin: 0 auto;
overflow: hidden;
display: block;
color: black;
text-align: center;
text-decoration: none;
font-family:'Bitter', serif;
font-style: italic;
font-size: 16px;
line-height: 32px;
}
.fancy a:before, .fancy a:after {
content:"";
display: inline-block;
position: relative;
height: .1em;
width: 50%;
border-top: 1px dotted black;
border-bottom: 1px dotted black;
margin-bottom: .25em;
}
.fancy a:before {
right: .5em;
margin-left: -50%;
}
.fancy a:after {
left: .5em;
margin-right: -50%;
}
/* This is the gradient I want to display in front of the border. The body will have a white background, so it will look like the border is fading out */
.fancy {
/* Safari 5.1, Chrome 10+ */
background: -webkit-linear-gradient(left, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
/* Firefox 3.6+ */
background: -moz-linear-gradient(left, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
/* IE 10 */
background: -ms-linear-gradient(left, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
/* Opera 11.10+ */
background: -o-linear-gradient(left, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
}
为了方便修改代码,这里是:http://jsfiddle.net/QEdxe/3/
有人知道怎么做吗?我已经尝试过绝对定位和 z-index,但我无法让渐变与虚线边框重叠..
【问题讨论】:
-
如果可能的话,我宁愿动态地在 css 中执行此操作。但我不知道这是否可以做到..