Is there any way to select elements which may contains text?
Something like this:
*:text {
font-size: 12px;
}
Run Code Online (Sandbox Code Playgroud)
I want to use it for my reset.css, but I can't find a way how to do it, so for now I use this code:
* {
font-size: 12px;
}
Run Code Online (Sandbox Code Playgroud)
This solution works for all text based elements (for example STRONG, P, A, etc.), but it also apply this style to non-text elements like IMG, OBJECT and others.
So I am wondering if is there any other solution to set CSS properties for all text based elements, but nothing else.
您不能使用 css 选择器根据元素是否包含文本来定位元素。另一方面,您可以查看为文本设置所需的全局字体大小或样式的最佳方式。
用你已经拥有的,
* {
font-size: 12px;
}
Run Code Online (Sandbox Code Playgroud)
这是将这种样式分配给 dom 中的所有内容。您可能不这么认为,但它正在将其应用于您的头部、正文、html 和页面上的任何标签。有几个选项可以解决这个问题,我将从最好到最差列出它们。
html, body { /* this allows the children to inherit this style */
font-size: 12px;
}
body * { /* assigns this style to every tag inside of your body tag */
font-size: 12px;
}
p, span, a, etc { /* you decided what tags would most likely contain text to apply that style */
font-size: 12px;
}
* { /* the worst option, applying that style to every tag */
font-size: 12px;
}
Run Code Online (Sandbox Code Playgroud)
我认为没有一种特定的方法可以使用伪选择器来定位基于文本的元素,但这是了解有关伪类的更多信息的好位置: http: //www.w3.org/TR/CSS2/selector。 html#伪类选择器
这是一篇关于重置的精彩文章: http: //www.css-reset.com/
创建 CSS 重置的绝佳资源: http://www.cssreset.com/
| 归档时间: |
|
| 查看次数: |
8693 次 |
| 最近记录: |