如何从 CSS 访问样式
如果使用CSS资源,我们可以从代码中的CSS定义中获取值吗?
例如,
.iv_menu_thumbnail {
display: block;
width: 24px;
height: 24px;
margin: 3px;
float: left;
cursor: pointer;
}`
我们可以通过代码知道 width
的值并且我想从我的 java 类之一进行访问吗?
提前致谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果这是您所要求的,这将获得元素的宽度。
就我而言,你无法从 css 声明中获取非数值。
但是你可以使用 jQuery 通过 jQuery 设置你自己的值,
所以如果你想设置一个新的 css 值,它看起来像这样。 (或覆盖它)
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
So it would look like this if you want to set a new css value. (or overwrite it)
据我所知,您只能检查应用了该属性的元素上的计算 CSS 属性。喜欢:
或
请注意,前者和后者不同 - 前者不包含计量单位,后者包含。
As far as I know, you can only inspect the computed CSS property on an element where this has been applied. Like:
or
Note that the former and the latter differ - the former does not contain the unit of measure, the latter does.
您可以在 Css 资源文件中包含一个变量,并使用该变量设置宽度属性,然后从代码中访问宽度变量。
CssResource
Css 资源文件
Java 代码
You can have a variables in your Css Resource file and set the width attribute with that variable, and then access the width varialbe from code.
CssResource
Css Resource file
Java Code