如题:在固定宽度的块级元素中,里面的内容最后一词组在宽度不够的情况下没有换行,如何让它换到下一行?
首先给出问题,截图如下:
@charset "utf-8";@import "E:/zSass/_config.scss";@import "E:/zSass/_reset.scss";@import "E:/zSass/_common.scss";a { color:#00f;}.demo { overflow:hidden; width:100px; margin-top:50px; @include center-block(); padding:5px; border:1px solid #000; background-color:#aaa; font-family:SimSun; line-height:20px;}
我们可以看出第一行和第二行由于宽度不够导致词组断开了,解决这个问题有两种方法。
方法一: display:inline-block;
@charset "utf-8";@import "E:/zSass/_config.scss";@import "E:/zSass/_reset.scss";@import "E:/zSass/_common.scss";a { color:#00f;}.demo { overflow:hidden; width:100px; margin-top:50px; @include center-block(); padding:5px; border:1px solid #000; background-color:#aaa; font-family:SimSun; line-height:20px; a { @include inline-block(); }}
方法二: float:left;white-space:nowrap;
@charset "utf-8";@import "E:/zSass/_config.scss";@import "E:/zSass/_reset.scss";@import "E:/zSass/_common.scss";a { color:#00f;}.demo { overflow:hidden; width:100px; margin-top:50px; @include center-block(); padding:5px; border:1px solid #000; background-color:#aaa; font-family:SimSun; line-height:20px; a { @include float(); margin-right:5px; white-space:nowrap; }}
测试浏览器:chrome/firefox/ie6-11