但不是绝对定位的元素

但不是绝对定位的元素

本文介绍了为什么你可以清除浮动元素,但不是绝对定位的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,如果你添加 float:left; 到一个元素,它被从流右移?据我所知, position:absolute; 也是如此,你可以用clearfix清除浮动的元素,但是你不能做任何事情关于绝对定位元素?

So, if you add float: left; to an element it is taken out of the flow right? And as far as I know this is also the case with position: absolute; so how is it that you can clear floated elements with a clearfix, but you can't do anything about absolutely positioned elements? What is the difference in how each are removed from the content flow?

推荐答案

不,浮动元素不会完全从内容流中移除流如绝对定位的元素,它们只是被提升到其他内容流动的元素。浮动元素的原始使用例如是文章中的图像;通过浮动图像,文章中的文本将在其周围流动。

No, floating elements are not taken completely out of the flow like absolutely positioned elements are, they are just promoted to the elements that other content flow around. The original use of floating elements was for example an image in an article; by floating the image the text in the article would flow around it.

注意:clearfix不用于清除浮动元素,它用于包含浮动元素在另一个元素。要清除浮动元素,只需使用 clear 样式。

Note: a clearfix is not used to clear floating elements, it's used to contain floating elements inside another element. To clear floating elements you simply use the clear style.

这篇关于为什么你可以清除浮动元素,但不是绝对定位的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 06:05