“内容:”的各种可能的用途CSS2/CSS3 中的属性
我试图找到一些关于 css 中 content:
属性的各种可能用途的最新信息,但只能在 2004 年左右的网络古代地下城中找到一些东西,所以我想我必须在又是 2011 年:
p:before {
content: url(dingdong.png);
}
p:before {
content: "some text ";
}
我对 :before
选择器和 content:
属性都很陌生,并且在这个问题上偶然听说了它,这个问题得到了非常有创意的回答可爱的女士:
如何通过 CSS 在 UL/LI html 列表中设置项目符号颜色,而不使用任何图像或 span 标签
只是发现内容的实际编码可能会出现一些问题:
因此,我的具体问题是:除了 url()
和 "text"
之外, 还有其他可能性吗?
非常感谢您的建议和想法。
I'm trying to find some uptodate info about various possible uses for content:
property in css but only find stuff in the ancients dungeons of the web dating from 2004 orso so I thought I have to ask this in 2011 again:
p:before {
content: url(dingdong.png);
}
p:before {
content: "some text ";
}
I'm very new to both the :before
selector as well as the content:
property and heard of it accidentally on this question which was answered very creatively by a lovely lady:
How to set Bullet colors in UL/LI html lists via CSS without using any images or span tags
Only to find out that some problems might occur concerning the actual encoding of the content:
li:before{ content: "■"; } How to Encode this Special Character as a Bullit in an Email Stationery?
And so my concrete question is: besides url()
and "text"
, are ther other possibilities?
Thanks very much for your suggestions and ideas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
哦,太多了,无法一一列举。一些最常见的情况是:
特殊编号,使用
counter()
函数,以及counter-reset
和counter-increment 属性
<前><代码>.foo:after {
内容: ””;
显示:块;
明确:两者;
}
显示属性,例如打印打印样式表中超链接的URL
添加不应该出现在 HTML 中的印刷装饰,因为它们是演示性的。例如,在我的博客中,我将其用于帖子或侧边栏链接之间的装饰。
将图标添加到超链接,具体取决于它们指向的位置,例如
添加指针以制作仅 CSS 的对话气泡:
<前><代码>.bubble {
位置:相对;
背景:银色;
}
.buble:之后{
内容: ””;
边框:10px实心透明;
顶部边框颜色:银色;
位置:绝对;
底部:-20px
}
还有很多很多其他的。
请注意:如果某些内容不是演示性的,它可能应该位于您的 HTML 中。用户将无法选择 CSS 生成的内容,屏幕阅读器将忽略它。
Oh, too many to list. Some of the most common cases are:
Special numbering, with the
counter()
function, along with thecounter-reset
andcounter-increment
propertiesPure CSS clearfix with:
Display attributes, eg to print URLs for hyperlinks in a print stylesheet
Add typographic ornaments that shouldn't be in the HTML because they're presentational. For example, in my blog, I've used it for the ornaments between posts or sidebar links.
Add icons to hyperlinks, depending on where they point, like
Adding a pointer to make a CSS-only speech bubble:
And many, many other.
Just beware: If something is not presentational, it should probably be in your HTML. Users will not be able to select CSS generated content, and screen readers will ignore it.
您还可以使用计数器。
请参阅 http://www.w3schools.com/css/tryit.asp?filename= trycss_content_counter
还可以显示所选元素的某个属性。
请参阅 http://jsfiddle.net/EcnM2/
您还可以添加或删除左引号和右引号。
w3schools 内容属性列表:http://www.w3schools.com/css/pr_gen_content.asp
You can also use a counter.
See http://www.w3schools.com/css/tryit.asp?filename=trycss_content_counter
You can also display a certain attribute of the element selected.
See http://jsfiddle.net/EcnM2/
You can also add or remove opening and closing quotes.
w3schools content property list: http://www.w3schools.com/css/pr_gen_content.asp
屏幕阅读器不会感知生成的内容,因此请注意可访问性问题。
content
非常有用,但在某些情况下,此文本应该位于 HTML 代码中,因为它传达信息而不仅仅是装饰性的(有点像 CSS 中的背景图像与信息丰富的img 带有非空 alt 属性)
编辑:忘记了 Eric Meyer 在 A List Apart 中关于 打印链接的 href 属性 以及他们的文本在内容的帮助下(随后是 JS 改进,仅供参考)
Generated content won't be perceived by screen readers so beware of accessibility issues.
content
is very useful but there are cases where this text should be in the HTML code because it conveys information and isn't only decorative (a bit like background images in CSS vs informativeimg
with a non-empty alt attribute)EDIT: forgot about Eric Meyer's article in A List Apart about printing the href attribute of links along with their text with the help of content (it was followed by a JS improvement, fyi)