惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
J
Java Code Geeks
雷峰网
雷峰网
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
V
Vulnerabilities – Threatpost
S
Securelist
The Hacker News
The Hacker News
The Register - Security
The Register - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
G
Google Developers Blog
Hugging Face - Blog
Hugging Face - Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
AI
AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Schneier on Security
Schneier on Security
N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
博客园 - 司徒正美
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
大猫的无限游戏
大猫的无限游戏
Security Latest
Security Latest
Engineering at Meta
Engineering at Meta
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
U
Unit 42
V
V2EX
V2EX - 技术
V2EX - 技术
L
LINUX DO - 最新话题
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
Recorded Future
Recorded Future
P
Privacy & Cybersecurity Law Blog
美团技术团队
小众软件
小众软件
F
Fortinet All Blogs

CSS | 酷 壳 - CoolShell

Chrome开发者工具的小技巧 | 酷 壳 - CoolShell 浏览器的渲染原理简介 | 酷 壳 - CoolShell 神奇的CSS形状 | 酷 壳 - CoolShell CSS 布局:40个教程、技巧、例子和最佳实践 | 酷 壳 - CoolShell Web开发中需要了解的东西 | 酷 壳 - CoolShell CSS图形 | 酷 壳 - CoolShell 一些有意思的贴子和工具 | 酷 壳 - CoolShell Web开发人员速查卡 | 酷 壳 - CoolShell 30+ Web下拉菜单 | 酷 壳 - CoolShell 40个很不错的CSS技术 | 酷 壳 - CoolShell 一些非常有意思的杂项资源 | 酷 壳 - CoolShell 写HTML和CSS的新方法 | 酷 壳 - CoolShell 纯CSS做的3D效果 | 酷 壳 - CoolShell 9个最常见IE的Bug及其fix | 酷 壳 - CoolShell
Web中的省略号 | 酷 壳 - CoolShell
陈皓 · 2009-12-15 · via CSS | 酷 壳 - CoolShell

在Web开发中,对于一种情况很常见。那就是,文本太长,而放置文本的容器不够长,而我们又不想让文本换行,所以,我们想使用省略号来解决这个问题。但是,在今天HTML的标准中并没有相关的标识或属性让你可以简单地完成这个事。但是我们可以使用CSS样式表来完成这个事,在IE,Safari,Chrome,Opera中都可以。但在Firefox中却不行,但我们可以使用jQuery来解决Firefox不兼容的问题。下面是相关的代码示例。

使用CSS设置省略号

overflow: hidden;
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
white-space: nowrap;
width: 100%;
  • overflow 属性是必需的,并且属性要是hidden。
  • white-space: nowrap 也是必需的。如果文本可以自动换行,就算是不可见,也不会有省略号的。因为文本换行了,所以没有超过容器的尺寸,所以也就不会有省略号了。
  •  width 属性仅在需要支持IE6时设置。 设置成100%仅是为了解决IE6的不兼容问题。(关于IE中的那些不兼容问题,你可以参看本站的《9个最常见IE的Bug及其fix》)
  • text-overflow: ellipsis 就是设置省略号了。目前还不是HTML的标准规范。其是由IE引入的,可以在IE6+,Safari 3.2+和Chrome上工作。
  • -o-text-overflow: ellipsis 是 Opera 支持的。可以在 Opera 9.0+使用。

使用jQuery设置省略号

正如前面所说过的,Firefox并不支持CSS中的那些省略号设置,因为那并不是标准的HTML规范。所以,我们需要使用jQuery的Javascript来干这个事。你可以下载由Devon Govett写的jQuery 省略号插件,于是,你可以简单的把”ellipsis”赋给某些元件或是CSS定义,如下所示:

[javascript]$(document).ready(function() {
    $(‘.ellipsis’).ellipsis();
}[/javascript]

或是

[javascript]$("span").ellipsis();[/javascript]

Loading...