javascript - 如何使div的顶部和底部透明

标签 javascript jquery css html

我正在制作一个内容比我想在高度上查看的内容长的 div,所以我使用了 20em 的高度,并制作了 overflow:scroll。这很好用,但我想给它添加一些效果。

我怎样才能使顶部和底部 50px 的不透明度为 0.7?所以当内容滚动“离开”时它会产生效果。

谢谢!

<div>
<ul>
   <li>long list here</li>
   <li>long list here</li>
   <li>long list here</li>
   <li>long list here</li>

</ul>

风格:

height:25em;
overflow:scroll;

最佳答案

DEMO

演示:

#wrapper {
    position: relative;
}
#wrapper:before, #wrapper:after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 30px; /* Height of the effect */
}
#wrapper:before {
    top: 0;
    /* Use your background color, assuming white: */
    background-image: linear-gradient(to bottom, rgba(255,255,255,1), rgba(255,255,255,0));
}
#wrapper:after {
    bottom: 0;
    /* Use your background color, assuming white: */
    background-image: linear-gradient(to top, rgba(255,255,255,1), rgba(255,255,255,0));
}
#mydiv {
    background: red;
    height: 20em;
    overflow: auto;
    border: 0 solid transparent;
    border-width: 10px 0; /* 10px to be able to read first and last lines */
}
<div id="wrapper">
    <div id="mydiv">
        Your content
    </div>
</div>

关于javascript - 如何使div的顶部和底部透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20156966/

相关文章:

javascript - 返回在字符串数组中找到的最大数字

PHP if 语句如果页面是用 ajax 加载的

html - Fontasic 图像未显示在网页中

javascript - 防止 DOM 元素折叠时页面跳转

javascript - Nodejs Promise 有更好的方法来处理 Promise 实现中发生的错误吗?

javascript - 如何在 TypeScript 中使用第一阶段 babel 插件

javascript - 检测何时将noVolume选项与jPlayer一起使用

javascript - 为什么这个 <div> 元素不会按照我希望的方式移动到使用 jQuery 的方式?

html - 导航上的下拉列表和元素之间的距离

CSS3 PIE.htc 不工作