如何从CSS访问样式 [英] how to access the styles from CSS
本文介绍了如何从CSS访问样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果使用CSS资源,我们可以从代码中的css定义中获取值吗?
例如
.iv_menu_thumbnail {
display:block;
width:24px;
height:24px;
margin:3px;
float:left;
光标:指针;
}`
我们可以通过代码知道宽度的值
并且我想从我的一个java类中访问?
感谢您提前致谢!
解决方案
var width = $('。iv_menu_thumbnail')。width();
console.log(width);
如果这是你所要求的,这将得到元素的宽度。
就我而言,您无法从css声明中获取非数值。
但是,您可以通过jQuery使用 p>
.css()
所以如果你想设置一个新的CSS值,它会看起来像这样。 (或覆盖它)
$(someelement).css('float','left');
Can we get the value from inside a css definition in the code if CSS resource is used?
e.g.
.iv_menu_thumbnail {
display: block;
width: 24px;
height: 24px;
margin: 3px;
float: left;
cursor: pointer;
}`
Can we know via code the value of width
and i want to access from one of my java class?
Thanks in advance
解决方案
var width = $('.iv_menu_thumbnail').width();
console.log(width);
This will get the width of the element if this is what youre asking for. As far as I'm concerned you cannot get non numerical values from a css declaration.
But you can set your own values via jQuery using the
.css()
So it would look like this if you want to set a new css value. (or overwrite it)
$(someelement).css('float', 'left');
这篇关于如何从CSS访问样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文