官术网_书友最值得收藏!

The float method

We can prevent elements from collapsing by floating the container to the left or to the right. Let's do this; let's add float: left or float: right to our secondary-section. Either will work:

.secondary-section { 
  margin-bottom: 50px; 
  background-color: #7EEEAF; 
  float: left; 
} 

Once we save this, we will see that we have the green background, so the collapse is no longer taking place, but the obvious problem is we've floated to the left. We wanted this div to be centered:

This method has an obvious drawback. There are some circumstances and some situations where it would be a perfect solution, but in this one, there's an obvious problem: we are no longer centered. Remove float: left from your CSS and explore my favorite, and I think the best, solution: the clearfix hack.

主站蜘蛛池模板: 东城区| 隆尧县| 九台市| 泰顺县| 贺兰县| 遂平县| 饶河县| 梁河县| 长乐市| 禹州市| 泾川县| 崇仁县| 巴彦淖尔市| 虎林市| 菏泽市| 湘潭市| 甘孜县| 广元市| 宿州市| 钦州市| 即墨市| 石首市| 沅江市| 龙岩市| 金坛市| 南平市| 乡宁县| 阿巴嘎旗| 通州市| 承德县| 西安市| 叶城县| 阳山县| 河池市| 南丰县| 焉耆| 鲁山县| 中牟县| 涞水县| 崇仁县| 崇州市|