固定宽度文字换行_html/css_WEB-ITnose

WBOY
Release: 2016-06-21 08:59:14
Original
1079 people have browsed it

如题:在固定宽度的块级元素中,里面的内容最后一词组在宽度不够的情况下没有换行,如何让它换到下一行?

首先给出问题,截图如下:

Html

      固定宽度文字换行 
Copy after login

Css

@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;}
Copy after login

我们可以看出第一行和第二行由于宽度不够导致词组断开了,解决这个问题有两种方法。

方法一: display:inline-block;

Css

@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(); }}
Copy after login

方法二: float:left;white-space:nowrap;

Css

@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; }}
Copy after login

测试浏览器:chrome/firefox/ie6-11

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!