CSS 淡化顶部和底部“边框" [英] CSS fading top and bottom "borders"

查看:60
本文介绍了CSS 淡化顶部和底部“边框"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看这个:http://jsfiddle.net/wjhnX/

我用这个 CSS 实现了它:

I achieved it with this CSS :

background-image: radial-gradient(#CCC, #FFF), radial-gradient(#CCC, #FFF);
background-size:    2px 100%;
background-position: 0 0, 100% 0;
background-repeat:  no-repeat;

这是否可行,但模拟的边框是上下,而不是左右?

Is this possible to do but the simulated borders would be top and bottom, not left and right ?

先谢谢了!

推荐答案

你想要这样的东西吗?

Demo(为您的内容留出一些喘息的空间,我使用了 margin 那里,只要确保它适用于 :before:after,所以如果你想分开,为每个单独声明边距, ps - 我把颜色调亮了)

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;
}

说明:我使用了 :before:after 伪有 content: "",所以它创建了一个块,你可以说里面有一个虚拟块元素...并进一步设置为 display: block,只要确保您使用 block 其他边距和 height 将没有效果.. 最后但并非最不重要的是,我使用带有 rgba 的渐变来控制渐变的 alpha/不透明度,这将在两端褪色

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

这篇关于CSS 淡化顶部和底部“边框"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆