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

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

Using the clear method

Let's solve this using the clear property. What we'll do at the end of secondary-section is add a class of clear to a new div, using the following code:

<div class="clear"></div> 

Next, we'll go into our CSS, and in the area reserved for global styles, underneath the ruleset targeting the wrapper class; this is where we'll create the clear selector and add clear: both:

/***************
Global
***************/
::-moz-selection {
background-color: #eb2428;
}
::selection {
background-color: #eb2428;
}
.wrapper {
margin: 0 auto;
width: 960px;
}
.clear {
clear: both;
}

So, if we save this and return to the browser, our background color will be green with a bottom margin of 50px. Everything is working very well:

However, we've added extra non-semantic markup to our page. We may even get an SEO deduction for this. Let's explore other ways to do this without adding the extra markup. Get rid of that extra markup we just added to our HTML:

<div class="clear"></div> <!-- delete this -->

Our collapse will return. Now we won't be able to see the green background anymore; that's how we know the collapse is there:

主站蜘蛛池模板: 永川市| 聊城市| 巴林右旗| 西盟| 阿拉善左旗| 琼海市| 竹北市| 辽阳市| 新巴尔虎左旗| 会同县| 新干县| 金乡县| 黔西县| 潼关县| 南澳县| 汤原县| 涿鹿县| 都兰县| 碌曲县| 北碚区| 恭城| 青龙| 长葛市| 辽宁省| 会泽县| 宜丰县| 荔波县| 友谊县| 吉木萨尔县| 那曲县| 盐城市| 民乐县| 云和县| 丹巴县| 河间市| 沾益县| 泊头市| 临泉县| 全州县| 青海省| 中卫市|