jQuery CSS calc()函数 [英] jquery CSS calc() function

查看:304
本文介绍了jQuery CSS calc()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰到了此页面 CSS链接 我忍不住喜欢这个想法来计算不同单位的结果... 但是我尝试了这个:

i came across this page CSS LINK i could't help but love the idea of that to calculate the outcome of different units... however i tried this :

$('selector').css({'width':'calc(100%-20px)'});

但是它不起作用……任何人都知道它是如何工作的,或者为什么不起作用?

but it doesn't work... anyone has any ideas how this works , or why doesn't this work?

推荐答案

jQuery不支持calc()值,任何当前的浏览器也不支持.

jQuery does not support the calc() value, and neither does any of the current browsers.

在此处查看比较: http://en.wikipedia.org/wiki/comparison_of_layout_engines_%28Cascading_Style_Sheets%29

在您的示例中,您可以仅在内部元素上使用边距:

In your example, yo can just use margins on the inner element instead:

<div class="parent"><div class="elem"></div></div>

.parent{
    width:100%;
    background:green;
}
.elem{
    margin: 0 10px;
    background:blue;
}

这样,.elem的宽度将为100%-20px.

This way, .elem will be 100% - 20px wide.

这篇关于jQuery CSS calc()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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