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

  • Mastering CSS
  • Rich Finelli
  • 262字
  • 2021-07-08 09:45:58

Collapsed containers

So, everything is great with the columns, except that if you try and scroll the page down, you will see that we are really tight to the bottom.

Let's see what happens when we add a margin-bottom property to the container that wraps around everything: secondary-section. Let's say margin-bottom: 40px:

/**************** 
3 columns 
****************/ 
.secondary-section { 
  margin-bottom: 40px; 
} 

If we save this, it really does nothing in the browser. The content is still sitting right at the bottom. Let me further illustrate this problem. If I had a background color of green, then you'd expect the entire background to be green:

.secondary-section { 
  margin-bottom: 40px; 
  background-color: green; 
} 

However, if we add the preceding code and save it, the background doesn't become green. So, let's actually inspect this element. Let's inspect secondary-section in the browser using Chrome's DevTools. We will see both margin-bottom and background-color are in the process of getting applied. But we don't see anything in green on the page:

When you put your mouse over the secondary-section element, you will see it highlights the space that it occupies in that peachy color on the screen (you'll see it as a different shade of gray in the following screenshot if you're looking at a printed copy):

The container has actually collapsed. This is what happens when all the elements inside a parent element are floated: the container collapses, floats are taken outside the normal flow, and the container has no height because of this.

Let's take a look and see what we can do to fix this.

主站蜘蛛池模板: 藁城市| 沂源县| 遂昌县| 万宁市| 昂仁县| 巴林右旗| 建昌县| 辽阳县| 介休市| 五家渠市| 淳安县| 陈巴尔虎旗| 株洲市| 南安市| 鄂托克前旗| 滦南县| 平武县| 瑞昌市| 尼勒克县| 滨海县| 安平县| 钟山县| 连云港市| 榆中县| 荔浦县| 卓资县| 昌图县| 东港市| 常宁市| 休宁县| 民县| 齐齐哈尔市| 静安区| 如东县| 牙克石市| 邵武市| 庄河市| 成武县| 定远县| 四平市| 丹江口市|