简体   繁体   English

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

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

I am making a div with a content longer than what I want to view in height, so I used a height of 20em, and made overflow:scroll.我正在制作一个内容长于我想要查看的高度的 div,所以我使用了 20em 的高度,并制作了溢出:滚动。 This work great, but I want to add some effect to it.这工作很好,但我想给它添加一些效果。

How can I do so the top and bottom 50px have a opacity of 0.7?我怎样才能使顶部和底部 50px 的不透明度为 0.7? so it gets a effect when the content is scrolled "away".所以当内容被滚动“离开”时它会产生效果。

Thanks!谢谢!

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

</ul>

Style:风格:

height:25em;
overflow:scroll;

DEMO演示

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>

You can add two layers at top and bottom, note it will cover your content so I suggest it takes no more than 20px.你可以在顶部和底部添加两层,注意它会覆盖你的内容,所以我建议它不超过 20px。 Here is an example with transparent covers, but you can use nice PNG gradient instead:这是一个带有透明封面的示例,但您可以使用漂亮的 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>

I think you may like this.我想你可能会喜欢这个。 Try this one.试试这个。

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

and my div is like我的 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.

an discere delenit.一个谨慎的错误。

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

相关问题 如何使滚动条透明并位于 div 之上 - How to make a scrollbar be transparent and on top of the div 如何使网站的底层对背景幻灯片透明? - How to make bottom top layer of website transparent to background slideshow? 如何使div顶部成为其他div的底部 - How do I make a div top to be the bottom of other div 如何重复增加div(顶部div和底部div)动态增加 - How to make dynamic increasing of divs (div at the top and div at the bottom) repeatedly 如何使一个div始终位于视图的底部并根据底部div调整顶部div的大小? - How to make one div always be at the bottom of the view and make top div resize based on bottom div? 如何根据用户的滚动方式将div粘贴到顶部或底部? - How to make a div stick to top or bottom, depending on how the user is scrolling? 如何使顶线短于底线(在div内) - How to make top line shorter than bottom line (within div) 使用背景视频淡化半透明和可滚动 div 的顶部和底部边缘 - Fading top and bottom edges of a semi transparent and scrollable div with a background video 我如何才能使粘性导航栏在其底部固定之前在英雄底部透明显示? - How can i make a sticky navbar appear transparent at the bottom of a hero before it becomes fixed at the top? 使第二个 div 从上到下滑动 - To make the second div slide from top to bottom
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM