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

  • Mastering CSS
  • Rich Finelli
  • 229字
  • 2021-07-08 09:45:59

Using overflow property with hidden value

The next method we'll look at is overflow: hidden. Go to your CSS and find the .secondary-section class. What we can do is add the overflow property with the value of hidden:

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

overflow: hidden is a true hack. It was never meant for remedying collapsed containers; it was meant for hiding any content image or text that overflowed its container. However, magically, overflow: hidden also clears the collapse. If we save our CSS and go to our site, we will see this is evident by the background, which is now green in color:

A small problem with overflow: hidden is that you may want the content to overflow the container, for instance, a drop-down menu or tooltip. The overflow: hidden hack will hide that overflow—no surprises there! It's a solution, but it may not always be ideal. For instance, in our exact scenario, we may want this octopus to kind of creep out of its container. Let's go into Chrome DevTools and give it margin-top: -50px. As you can see, now the top of the image is no longer showing and the overflow is hidden:

So that's not a good fix for us. Let's delete that overflow: hidden declaration from our CSS file and look at the next method: the float method.

主站蜘蛛池模板: 平利县| 咸阳市| 榆林市| 温宿县| 菏泽市| 灵石县| 涡阳县| 屯昌县| 礼泉县| 苗栗市| 滁州市| 中江县| 汽车| 南阳市| 富民县| 吴忠市| 怀安县| 哈尔滨市| 鹤山市| 繁昌县| 苍南县| 天长市| 富川| 定西市| 鲁甸县| 红安县| 南昌市| 娱乐| 衡东县| 新田县| 淮南市| 和静县| 额尔古纳市| 靖安县| 宁陵县| 布尔津县| 博湖县| 封开县| 鹤庆县| 策勒县| 康保县|