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

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.

主站蜘蛛池模板: 喀喇沁旗| 彭山县| 久治县| 金华市| 呼和浩特市| 依兰县| 隆尧县| 汉中市| 宜阳县| SHOW| 仁寿县| 达尔| 岳阳市| 新宁县| 滦南县| 阳朔县| 崇礼县| 如皋市| 宜宾市| 和政县| 洪泽县| 南充市| 元阳县| 石景山区| 荆门市| 洛扎县| 阜宁县| 龙南县| 松滋市| 日土县| 师宗县| 花莲市| 墨玉县| 涟水县| 松江区| 鹤壁市| 苍山县| 抚州市| 溧阳市| 南和县| 读书|