在css中的字符串连接 [英] string concatenation in css

查看:111
本文介绍了在css中的字符串连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在css中实现以下。我如何以一种工作方式在IE8 +

I want to achieve the following in css. How do i do it in a way that works in IE8+

url('../img/icons/' + attr('type') + '_10.png')


推荐答案

您不能以您建议的方式进行动态字符串插值,但如果您的 [type] 属性的可能值有限,您可以创建每个样式:

You can't do dynamic string interpolation in the way that you're suggesting, but if you have a limited number of possible values for the [type] attribute, you could create styles for each one:

.your .selector[type="foo"] {
    background-image: url('../img/icons/foo_10.png');
}
.your .selector[type="bar"] {
    background-image: url('../img/icons/bar_10.png');
}
.your .selector[type="baz"] {
    background-image: url('../img/icons/baz_10.png');
}

如果您的类型数量不合理,需要提出比我在此列出的更好的解决方案。

If you've got an unreasonable number of types, then you'll probably need to come up with a better solution than I've listed here.

这篇关于在css中的字符串连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆