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

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.

主站蜘蛛池模板: 将乐县| 文成县| 博白县| 彭阳县| 乌海市| 石狮市| 德化县| 五莲县| 盐边县| 甘洛县| 锡林郭勒盟| 友谊县| 博罗县| 通州区| 呼图壁县| 屯门区| 张家港市| 康保县| 翁源县| 淳化县| 丹凤县| 阿克陶县| 雅安市| 潜山县| 阿坝县| 肇源县| 哈密市| 台北县| 樟树市| 永清县| 玉门市| 长海县| 防城港市| 五常市| 宣汉县| 和田市| 青岛市| 望都县| 东乡| 新津县| 静宁县|