简体   繁体   English

如何使用jQuery在CSS文件中检测百分比宽度

[英]how to detect percent width in css file with jquery

I want get width from css file with jquery but when use this method : 我想用jQuery从CSS文件中获取宽度,但是当使用这种方法时:

$('element').width() OR $('element').css('width'); $('element').width() $('element').css('width'); get pixel size element but in css file this element has percent size .... 获取像素大小元素,但在css文件中此元素具有百分比大小....

how to get it. 如何获得它。 html : html:

<div id="content"></div>

css 的CSS

#content{width:50%}

For the sake of being bored: 为了无聊:

var mywidth = $('#content').width(),
    parentwidth = $('#content').parent().width(),
    percentagewidth = (mywidth*100)/parentwidth;
    alert(precentagewidth+"%");

==Rounding the number== ==四舍五入==

Math.round(precentagewidth)

Math.round() documentation. Math.round()文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM