繁体   English   中英

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

[英]How to make top and bottom of div transparent

我正在制作一个内容长于我想要查看的高度的 div,所以我使用了 20em 的高度,并制作了溢出:滚动。 这工作很好,但我想给它添加一些效果。

我怎样才能使顶部和底部 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;

演示

演示:

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

你可以在顶部和底部添加两层,注意它会覆盖你的内容,所以我建议它不超过 20px。 这是一个带有透明封面的示例,但您可以使用漂亮的 PNG 渐变代替:

 .fixed_height { position: relative; } .fixed_height_content { padding: 20px 0; height: 100px; overflow-y: scroll; } .cover_top { position: absolute; left: 0; top: 0; right: 0; height: 20px; background: red; opacity: .3; } .cover_bottom { position: absolute; left: 0; bottom: 0; right: 0; height: 20px; background: red; opacity: .3; }
 <!doctype html> <html> <head> <meta charset="utf-8"> <title>Opacity</title> <style type="text/css"> </style> </head> <body> <div class="fixed_height"> <div class="fixed_height_content"> <p>Some content<br />more<br />more<br />more<br />more</p> <p>Some content<br />more<br />more<br />more<br />more</p> <p>Some content<br />more<br />more<br />more<br />more</p> <p>Some content<br />more<br />more<br />more<br />more</p> </div> <div class="cover_top"></div> <div class="cover_bottom"></div> </div> </body> </html>

我想你可能会喜欢这个。 试试这个。

<style>    
#boxBorder {
    height: 3em;
    overflow: hidden;
    }
#boxBorder:hover {
height: 5em;
overflow: hidden;
}
#boxBorder:after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 100px; 
    bottom: 0;
    background-image: linear-gradient(to top, rgba(255,255,255,1), rgba(256,256,256,0));   
}
</style>

我的 div 就像

<div id="boxBorder">
    Vis meis ipsum cu, est ad modus facilis, ut est modus alienum consulatu. Mel ut primis dissentias. Doming omittam necessitatibus eam ei, simul vocibus complectitur at eam. Aliquid dolorem laboramus pri et. Porro utroque facilis ex has, pro eripuit ullamcorper te, an audiam civibus voluptaria mei.

    Consul iuvaret te eam. Eu usu modus nonumy nostrud, his ne facilis maiestatis. Nec clita nonumes ea, solet noluisse vix cu. Te vel altera verterem sapientem, quo corrumpit theophrastus ne.
    Quo iusto exerci assentior cu, ius erat velit timeam ea. Te modo offendit consectetuer has, id ius utamur quaerendum. Ut choro neglegentur nec, ea iusto feugait est. Feugait reprimique mel id, mel ad indoctum definitionem, nostrum apeirian ad pro.

一个谨慎的错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM