使用CSS清除修复和uncollapse边缘没有副作用

使用CSS清除修复和uncollapse边缘没有副作用

本文介绍了使用CSS清除修复和uncollapse边缘没有副作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下原因是什么是一般使用不含副作用的CSS修复和解除边距的好方法?副作用(并希望避免):

The following cause side effects (and would like to avoid them):


  • 设置 overflow:hidden overflow:auto
    剪辑 box-shadow ,CSS transforms和其他内容显示在箱子外面。因此,它不能在多种情况下使用(但其他工作效果很好)。

  • 设置 border padding :明显的定位/尺寸效果。

  • Setting overflow: hidden or overflow: auto:Clips box-shadow, CSS transforms, and other content one may want to show outside the box. Thus it can't be used in several cases (but otherwise works great).
  • Setting border or padding: Obvious positioning/sizing effects.

推荐答案

和崩溃修复(基于),并添加了未展开的边距:

The clear and collapse fix, based on this clear fix, with added margin uncollapse:

.group:before, /* :before to uncollapse the top margin */
.group:after{
    display: block;
    clear: both; /* clear fix */
    content: "\a0 "; /*   - just a space doesn't uncollapse margins */
    visibility: hidden; /* make sure not to show anything */
    height: 0;
}
.group{
    zoom: 1; /* solves it all for IE < 8, and doesn't hurt other browsers */
}

演示:,

请注意, content:\a0; 等效于& nbsp; 非空格字符(例如),以便在选择块并复制时,您不会获得额外的可见字符

Note that content: "\a0 "; is equivalent to &nbsp; and is used instead of a non-whitespace character (eg .) so that when you select the block and copy it, you do not get extra visible characters, which otherwise happens in some browsers (for example IE9).

此解决方案的缺点是:


  • :before :after 之后定义,因此需要特别注意,

  • 对于您要应用此修正的每个新选择器,必须指定选择器3次。

  • 不是很短/

  • :before and :after are defined, so special care needs to be taken if they are to be used.
  • For every new selector you want to have this fix applied to you have to specify the selector 3 times.
  • Not very short/trivial.

类似的解决方案由 YUI,但不包含& nbsp;

这篇关于使用CSS清除修复和uncollapse边缘没有副作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!