简体   繁体   English

如何剪辑浮动内容

[英]How to clip floated content

The following code snippet displays some headlines, with some icons floated on the left.下面的代码片段显示了一些标题,一些图标漂浮在左边。 The parent div has a defined height, with scroll:auto set.父 div 具有定义的高度,并设置了scroll:auto

Currently, scrolling to the bottom looks like this:目前,滚动到底部看起来像这样:

前

However, I'd like to clip off the icons when the text entries end, so when scrolling to the bottom, it looks like this:但是,我想在文本条目结束时剪掉图标,所以当滚动到底部时,它看起来像这样:

后

The reason for the use of float is so that when there are not many icons, the text flows like this:之所以使用float ,是为了在图标不多的时候,文字是这样流动的:

在此处输入图像描述

 .parent { position: absolute; height: 100px; width: 400px; overflow: scroll; }.content { background-color: cyan; padding: 6px; }.icon { float: left; clear: both; background-color: lightpink; width: 38px; height: 38px; margin-right: 8px; margin-bottom: 6px; }.entry { font-size: 18px; }
 <div class="parent"> <div class="content"> <img class="icon"> <img class="icon"> <img class="icon"> <img class="icon"> <div class="entry">Lorem ipsum dolor sit amet, consectetur adipiscing elit</div> <div class="entry">Quisque eleifend viverra risus, nec maximus nisi vestibulum eu</div> <div class="entry">Mauris in libero lacus</div> </div> </div>

Just smack a overflow: clip on your .content along with the sexy overflow-clip-margin: content-box .只需在您的.content上添加一个overflow: clip以及性感的overflow-clip-margin: content-box

Note on overflow-clip-margin : Safari doesn't support it (yet).关于overflow-clip-margin注意事项: Safari 不支持它(目前)。 Quick edit: Firefox has some issues with overflow-clip-margin 's visual-box property too.快速编辑: Firefox 在overflow-clip-marginvisual-box属性方面也存在一些问题 My bad!我的错!

Without it, the images are still clipped but without caring about your .content padding .没有它,图像仍然被裁剪但不关心你的.content padding Shouldn't be an issue if your text isn't actually behind a cyan background-color ;如果您的文本实际上不在cyan background-color后面,那应该不是问题; it's hard to tell on a white background.在白色背景上很难分辨。

 .parent { position: absolute; height: 100px; width: 400px; overflow: scroll; }.content { background-color: cyan; padding: 6px; overflow: clip; overflow-clip-margin: content-box; }.icon { float: left; clear: both; background-color: lightpink; width: 38px; height: 38px; margin-right: 8px; margin-bottom: 6px; }.entry { font-size: 18px; }
 <div class="parent"> <div class="content"> <img class="icon"> <img class="icon"> <img class="icon"> <img class="icon"> <div class="entry">Lorem ipsum dolor sit amet, consectetur adipiscing elit</div> <div class="entry">Quisque eleifend viverra risus, nec maximus nisi vestibulum eu</div> <div class="entry">Mauris in libero lacus</div> </div> </div>

 .parent { position: absolute; height: 100px; width: 400px; overflow: scroll; }.content { background-color: cyan; padding: 6px 6px 0 6px; overflow: hidden; position: relative; border-bottom: 8px solid cyan; /* same color */ }.icons, .entries { display: flex; flex-direction: column; }.icons { position: absolute; top: 8px; left: 8px; }.entries { margin-left: 56px; /* icon width '38' + icon left '8' and right '8' distance */ }.icon { background-color: lightpink; width: 38px; height: 38px; margin-bottom: 6px; }.entry { font-size: 18px; }
 <div class="parent"> <div class="content"> <div class="icons"> <img class="icon"> <img class="icon"> <img class="icon"> <img class="icon"> </div> <div class="entries"> <div class="entry">Lorem ipsum dolor sit amet, consectetur adipiscing elit</div> <div class="entry">Quisque eleifend viverra risus, nec maximus nisi vestibulum eu</div> <div class="entry">Mauris in libero lacus</div> </div> </div> </div>

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

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